summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1997-10-22 11:15:14 +0000
committerAndrew Tridgell <tridge@samba.org>1997-10-22 11:15:14 +0000
commit8d1993c71a5d5d32636f62ba9b9a9009ec74d730 (patch)
treef16a3cde49a649c3f984894466ca277ac7109f80
parent178e27de0791c1ff3268cb456ed5c5efc9ac2a01 (diff)
downloadsamba-8d1993c71a5d5d32636f62ba9b9a9009ec74d730.tar.gz
shared memory code cleanups (partly preparing for a possible sysV
shared memory implementation)
-rw-r--r--source/include/proto.h29
-rw-r--r--source/include/smb.h19
-rw-r--r--source/locking/locking_shm.c32
-rw-r--r--source/locking/shmem.c44
4 files changed, 68 insertions, 56 deletions
diff --git a/source/include/proto.h b/source/include/proto.h
index 4613137d0d5..149009685e8 100644
--- a/source/include/proto.h
+++ b/source/include/proto.h
@@ -6,6 +6,16 @@
BOOL check_access(int snum);
BOOL allow_access(char *deny_list,char *allow_list,char *cname,char *caddr);
+/*The following definitions come from asyncdns.c */
+
+int asyncdns_fd(void);
+void start_async_dns(void);
+void run_dns_queue(void);
+BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question,
+ struct name_record **n);
+BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question,
+ struct name_record **n);
+
/*The following definitions come from charcnv.c */
char *unix2dos_format(char *str,BOOL overwrite);
@@ -420,8 +430,8 @@ void remove_name(struct subnet_record *d, struct name_record *n);
struct name_record *find_name(struct name_record *n,
struct nmb_name *name, int search);
struct name_record *find_name_search(struct subnet_record **d,
- struct nmb_name *name,
- int search, struct in_addr ip);
+ struct nmb_name *name,
+ int search, struct in_addr ip);
void dump_names(void);
void load_netbios_names(void);
void remove_netbios_name(struct subnet_record *d,
@@ -432,7 +442,6 @@ struct name_record *add_netbios_entry(struct subnet_record *d,
int ttl, enum name_source source, struct in_addr ip,
BOOL new_only,BOOL wins);
void expire_names(time_t t);
-struct name_record *dns_name_search(struct nmb_name *question, int Time);
/*The following definitions come from namedbresp.c */
@@ -842,15 +851,13 @@ int construct_reply(char *inbuf,char *outbuf,int size,int bufsize);
/*The following definitions come from shmem.c */
-BOOL smb_shm_create_hash_table( unsigned int size );
-BOOL smb_shm_open( char *file_name, int size);
+BOOL smb_shm_open(char *file_name, int size);
BOOL smb_shm_close( void );
-smb_shm_offset_t smb_shm_alloc(int size);
-BOOL smb_shm_free(smb_shm_offset_t offset);
-smb_shm_offset_t smb_shm_get_userdef_off(void);
-BOOL smb_shm_set_userdef_off(smb_shm_offset_t userdef_off);
-void *smb_shm_offset2addr(smb_shm_offset_t offset);
-smb_shm_offset_t smb_shm_addr2offset(void *addr);
+int smb_shm_alloc(int size);
+BOOL smb_shm_free(int offset);
+int smb_shm_get_userdef_off(void);
+void *smb_shm_offset2addr(int offset);
+int smb_shm_addr2offset(void *addr);
BOOL smb_shm_lock_hash_entry( unsigned int entry);
BOOL smb_shm_unlock_hash_entry( unsigned int entry );
BOOL smb_shm_get_usage(int *bytes_free,
diff --git a/source/include/smb.h b/source/include/smb.h
index 0965b6b90b4..c982e3e78d1 100644
--- a/source/include/smb.h
+++ b/source/include/smb.h
@@ -63,8 +63,7 @@
typedef int BOOL;
/* offset in shared memory */
-typedef int smb_shm_offset_t;
-#define NULL_OFFSET (smb_shm_offset_t)(0)
+#define NULL_OFFSET (int)(0)
/* limiting size of ipc replies */
#define REALLOC(ptr,size) Realloc(ptr,MAX((size),4*1024))
@@ -1273,6 +1272,22 @@ struct share_ops {
void (*status)(FILE *);
};
+/* each implementation of the shared memory code needs
+ to support the following operations */
+struct shmem_ops {
+ BOOL (*open)(char *, int );
+ BOOL (*close)( void );
+ int (*alloc)(int );
+ BOOL (*free)(int );
+ int (*get_userdef_off)(void);
+ void *(*offset2addr)(int );
+ int (*addr2offset)(void *addr);
+ BOOL (*lock_hash_entry)(unsigned int);
+ BOOL (*unlock_hash_entry)( unsigned int );
+ BOOL (*get_usage)(int *,int *,int *);
+};
+
+
/* this is used for smbstatus */
struct connect_record
{
diff --git a/source/locking/locking_shm.c b/source/locking/locking_shm.c
index 47074cff6bc..8383b687e41 100644
--- a/source/locking/locking_shm.c
+++ b/source/locking/locking_shm.c
@@ -42,19 +42,19 @@ extern files_struct Files[];
/* share mode record pointed to in shared memory hash bucket */
typedef struct
{
- smb_shm_offset_t next_offset; /* offset of next record in chain from hash bucket */
+ int next_offset; /* offset of next record in chain from hash bucket */
int locking_version;
int32 st_dev;
int32 st_ino;
int num_share_mode_entries;
- smb_shm_offset_t share_mode_entries; /* Chain of share mode entries for this file */
+ int share_mode_entries; /* Chain of share mode entries for this file */
char file_name[1];
} share_mode_record;
/* share mode entry pointed to by share_mode_record struct */
typedef struct
{
- smb_shm_offset_t next_share_mode_entry;
+ int next_share_mode_entry;
share_mode_entry e;
} shm_share_mode_entry;
@@ -89,7 +89,7 @@ get all share mode entries in shared memory for a dev/inode pair.
static int shm_get_share_modes(int cnum, int token, uint32 dev, uint32 inode,
share_mode_entry **old_shares)
{
- smb_shm_offset_t *mode_array;
+ int *mode_array;
unsigned int hash_entry = HASH_ENTRY(dev, inode);
share_mode_record *file_scanner_p;
share_mode_record *file_prev_p;
@@ -111,7 +111,7 @@ static int shm_get_share_modes(int cnum, int token, uint32 dev, uint32 inode,
return 0;
}
- mode_array = (smb_shm_offset_t *)smb_shm_offset2addr(smb_shm_get_userdef_off());
+ mode_array = (int *)smb_shm_offset2addr(smb_shm_get_userdef_off());
if(mode_array[hash_entry] == NULL_OFFSET)
{
@@ -267,7 +267,7 @@ del the share mode of a file.
static void shm_del_share_mode(int token, int fnum)
{
uint32 dev, inode;
- smb_shm_offset_t *mode_array;
+ int *mode_array;
unsigned int hash_entry;
share_mode_record *file_scanner_p;
share_mode_record *file_prev_p;
@@ -290,7 +290,7 @@ static void shm_del_share_mode(int token, int fnum)
return;
}
- mode_array = (smb_shm_offset_t *)smb_shm_offset2addr(smb_shm_get_userdef_off());
+ mode_array = (int *)smb_shm_offset2addr(smb_shm_get_userdef_off());
if(mode_array[hash_entry] == NULL_OFFSET)
{
@@ -408,12 +408,12 @@ static BOOL shm_set_share_mode(int token, int fnum, uint16 port, uint16 op_type)
{
files_struct *fs_p = &Files[fnum];
int32 dev, inode;
- smb_shm_offset_t *mode_array;
+ int *mode_array;
unsigned int hash_entry;
share_mode_record *file_scanner_p;
share_mode_record *file_prev_p;
shm_share_mode_entry *new_entry_p;
- smb_shm_offset_t new_entry_offset;
+ int new_entry_offset;
BOOL found = False;
dev = fs_p->fd_ptr->dev;
@@ -429,7 +429,7 @@ static BOOL shm_set_share_mode(int token, int fnum, uint16 port, uint16 op_type)
return False;
}
- mode_array = (smb_shm_offset_t *)smb_shm_offset2addr(smb_shm_get_userdef_off());
+ mode_array = (int *)smb_shm_offset2addr(smb_shm_get_userdef_off());
file_scanner_p = (share_mode_record *)smb_shm_offset2addr(mode_array[hash_entry]);
file_prev_p = file_scanner_p;
@@ -453,7 +453,7 @@ static BOOL shm_set_share_mode(int token, int fnum, uint16 port, uint16 op_type)
{
/* We must create a share_mode_record */
share_mode_record *new_mode_p = NULL;
- smb_shm_offset_t new_offset = smb_shm_alloc( sizeof(share_mode_record) +
+ int new_offset = smb_shm_alloc( sizeof(share_mode_record) +
strlen(fs_p->name) + 1);
if(new_offset == NULL_OFFSET)
{
@@ -482,7 +482,7 @@ inode %d in hash bucket %d\n", fs_p->name, dev, inode, hash_entry));
new_entry_offset = smb_shm_alloc( sizeof(shm_share_mode_entry));
if(new_entry_offset == NULL_OFFSET)
{
- smb_shm_offset_t delete_offset = mode_array[hash_entry];
+ int delete_offset = mode_array[hash_entry];
DEBUG(0,("ERROR:set_share_mode (FAST_SHARE_MODES): smb_shm_alloc fail 1!\n"));
/* Unlink the damaged record */
mode_array[hash_entry] = file_scanner_p->next_offset;
@@ -528,7 +528,7 @@ Remove an oplock port and mode entry from a share mode.
static BOOL shm_remove_share_oplock(int fnum, int token)
{
uint32 dev, inode;
- smb_shm_offset_t *mode_array;
+ int *mode_array;
unsigned int hash_entry;
share_mode_record *file_scanner_p;
share_mode_record *file_prev_p;
@@ -551,7 +551,7 @@ static BOOL shm_remove_share_oplock(int fnum, int token)
return False;
}
- mode_array = (smb_shm_offset_t *)smb_shm_offset2addr(smb_shm_get_userdef_off());
+ mode_array = (int *)smb_shm_offset2addr(smb_shm_get_userdef_off());
if(mode_array[hash_entry] == NULL_OFFSET)
{
@@ -641,10 +641,10 @@ share mode system
static int shm_share_forall(void (*fn)(share_mode_entry *, char *))
{
int i, count=0;
- smb_shm_offset_t *mode_array;
+ int *mode_array;
share_mode_record *file_scanner_p;
- mode_array = (smb_shm_offset_t *)smb_shm_offset2addr(smb_shm_get_userdef_off());
+ mode_array = (int *)smb_shm_offset2addr(smb_shm_get_userdef_off());
for( i = 0; i < lp_shmem_hash_size(); i++) {
smb_shm_lock_hash_entry(i);
diff --git a/source/locking/shmem.c b/source/locking/shmem.c
index bbb11f215a0..9daca3e4829 100644
--- a/source/locking/shmem.c
+++ b/source/locking/shmem.c
@@ -43,8 +43,8 @@ struct SmbShmHeader
int smb_shm_version;
int total_size; /* in bytes */
BOOL consistent;
- smb_shm_offset_t first_free_off;
- smb_shm_offset_t userdef_off; /* a userdefined offset. can be used to store root of tree or list */
+ int first_free_off;
+ int userdef_off; /* a userdefined offset. can be used to store root of tree or list */
struct { /* a cell is a range of bytes of sizeof(struct SmbShmBlockDesc) size */
int cells_free;
int cells_used;
@@ -55,7 +55,7 @@ struct SmbShmHeader
#define SMB_SHM_NOT_FREE_OFF (-1)
struct SmbShmBlockDesc
{
- smb_shm_offset_t next; /* offset of next block in the free list or SMB_SHM_NOT_FREE_OFF when block in use */
+ int next; /* offset of next block in the free list or SMB_SHM_NOT_FREE_OFF when block in use */
int size; /* user size in BlockDescSize units */
};
@@ -141,10 +141,9 @@ static BOOL smb_shm_global_unlock(void)
* Function to create the hash table for the share mode entries. Called
* when smb shared memory is global locked.
*/
-
-BOOL smb_shm_create_hash_table( unsigned int size )
+static BOOL smb_shm_create_hash_table( unsigned int size )
{
- size *= sizeof(smb_shm_offset_t);
+ size *= sizeof(int);
smb_shm_global_lock();
smb_shm_header_p->userdef_off = smb_shm_alloc( size );
@@ -381,7 +380,7 @@ static void smb_shm_solve_neighbors(struct SmbShmBlockDesc *head_p )
-BOOL smb_shm_open( char *file_name, int size)
+BOOL smb_shm_open(char *file_name, int size)
{
int filesize;
BOOL created_new = False;
@@ -533,13 +532,13 @@ BOOL smb_shm_close( void )
return True;
}
-smb_shm_offset_t smb_shm_alloc(int size)
+int smb_shm_alloc(int size)
{
unsigned num_cells ;
struct SmbShmBlockDesc *scanner_p;
struct SmbShmBlockDesc *prev_p;
struct SmbShmBlockDesc *new_p;
- smb_shm_offset_t result_offset;
+ int result_offset;
if( !smb_shm_header_p )
@@ -637,7 +636,7 @@ smb_shm_offset_t smb_shm_alloc(int size)
-BOOL smb_shm_free(smb_shm_offset_t offset)
+BOOL smb_shm_free(int offset)
{
struct SmbShmBlockDesc *header_p ; /* pointer to header of block to free */
struct SmbShmBlockDesc *scanner_p ; /* used to scan the list */
@@ -716,7 +715,7 @@ BOOL smb_shm_free(smb_shm_offset_t offset)
}
}
-smb_shm_offset_t smb_shm_get_userdef_off(void)
+int smb_shm_get_userdef_off(void)
{
if (!smb_shm_header_p)
return NULL_OFFSET;
@@ -724,16 +723,7 @@ smb_shm_offset_t smb_shm_get_userdef_off(void)
return smb_shm_header_p->userdef_off;
}
-BOOL smb_shm_set_userdef_off(smb_shm_offset_t userdef_off)
-{
- if (!smb_shm_header_p)
- return False;
- else
- smb_shm_header_p->userdef_off = userdef_off;
- return True;
-}
-
-void *smb_shm_offset2addr(smb_shm_offset_t offset)
+void *smb_shm_offset2addr(int offset)
{
if (offset == NULL_OFFSET )
return (void *)(0);
@@ -744,7 +734,7 @@ void *smb_shm_offset2addr(smb_shm_offset_t offset)
return (void *)((char *)smb_shm_header_p + offset );
}
-smb_shm_offset_t smb_shm_addr2offset(void *addr)
+int smb_shm_addr2offset(void *addr)
{
if (!addr)
return NULL_OFFSET;
@@ -752,7 +742,7 @@ smb_shm_offset_t smb_shm_addr2offset(void *addr)
if (!smb_shm_header_p)
return NULL_OFFSET;
- return (smb_shm_offset_t)((char *)addr - (char *)smb_shm_header_p);
+ return (int)((char *)addr - (char *)smb_shm_header_p);
}
/*******************************************************************
@@ -761,7 +751,7 @@ smb_shm_offset_t smb_shm_addr2offset(void *addr)
BOOL smb_shm_lock_hash_entry( unsigned int entry)
{
- int start = (smb_shm_header_p->userdef_off + (entry * sizeof(smb_shm_offset_t)));
+ int start = (smb_shm_header_p->userdef_off + (entry * sizeof(int)));
if (smb_shm_fd < 0)
{
@@ -776,7 +766,7 @@ BOOL smb_shm_lock_hash_entry( unsigned int entry)
}
/* Do an exclusive wait lock on the 4 byte region mapping into this entry */
- if (fcntl_lock(smb_shm_fd, F_SETLKW, start, sizeof(smb_shm_offset_t), F_WRLCK) == False)
+ if (fcntl_lock(smb_shm_fd, F_SETLKW, start, sizeof(int), F_WRLCK) == False)
{
DEBUG(0,("ERROR smb_shm_lock_hash_entry : fcntl_lock failed with code %s\n",strerror(errno)));
return False;
@@ -792,7 +782,7 @@ BOOL smb_shm_lock_hash_entry( unsigned int entry)
BOOL smb_shm_unlock_hash_entry( unsigned int entry )
{
- int start = (smb_shm_header_p->userdef_off + (entry * sizeof(smb_shm_offset_t)));
+ int start = (smb_shm_header_p->userdef_off + (entry * sizeof(int)));
if (smb_shm_fd < 0)
{
@@ -807,7 +797,7 @@ BOOL smb_shm_unlock_hash_entry( unsigned int entry )
}
/* Do a wait lock on the 4 byte region mapping into this entry */
- if (fcntl_lock(smb_shm_fd, F_SETLKW, start, sizeof(smb_shm_offset_t), F_UNLCK) == False)
+ if (fcntl_lock(smb_shm_fd, F_SETLKW, start, sizeof(int), F_UNLCK) == False)
{
DEBUG(0,("ERROR smb_shm_unlock_hash_entry : fcntl_lock failed with code %s\n",strerror(errno)));
return False;