r3057: - moved the idtree.c code into lib/
authorAndrew Tridgell <tridge@samba.org>
Tue, 19 Oct 2004 07:08:35 +0000 (07:08 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:01:54 +0000 (13:01 -0500)
- converted the tid handling to use a idtree instead of bitmaps
(This used to be commit 4220914179d10132057216650b65ed7f7679717e)

source4/lib/basic.mk
source4/lib/idtree.c [moved from source4/ntvfs/common/idtree.c with 100% similarity]
source4/ntvfs/posix/config.mk
source4/smb_server/conn.c
source4/smb_server/smb_server.h
source4/smbd/rewrite.c
source4/torture/vfstest.c

index b6f30b6feb1385fd0432082e7b7fe0652e3a11b3..d525f5f156d7ce29a2dd78ae9b4cdfca380ae5ac 100644 (file)
@@ -48,7 +48,8 @@ ADD_OBJ_FILES = \
                lib/crypto/hmacmd5.o \
                lib/crypto/md4.o \
                lib/db_wrap.o \
-               lib/server_mutex.o 
+               lib/server_mutex.o \
+               lib/idtree.o
 REQUIRED_SUBSYSTEMS = \
                LIBTDB CHARSET
 # End SUBSYSTEM LIBBASIC
index 732e896d2b1278285962847649382acbd5af6a29..b6ba073a99e35d4d9a111b087d4328a942227134 100644 (file)
@@ -22,7 +22,6 @@ ADD_OBJ_FILES = \
                ntvfs/posix/pvfs_shortname.o \
                ntvfs/posix/pvfs_lock.o \
                ntvfs/posix/pvfs_wait.o \
-               ntvfs/common/idtree.o \
                ntvfs/common/brlock.o
 # End MODULE ntvfs_posix
 ################################################
index 1872d9b9d42bdad5a0a68813bb992ae859e895aa..78ecfec8966910c406e881cfd0f4e3e02c541c7f 100644 (file)
    per-client basis. Thus any one machine can't connect to more than
    MAX_CONNECTIONS services, but any number of machines may connect at
    one time. */
-#define MAX_CONNECTIONS 128
+#define MAX_CONNECTIONS 1024
 
 /****************************************************************************
 init the tcon structures
 ****************************************************************************/
 void conn_init(struct smbsrv_connection *smb_conn)
 {
-       smb_conn->tree.bmap = bitmap_allocate(MAX_CONNECTIONS);
+       smb_conn->tree.idtree_tid = idr_init(smb_conn);
 }
 
-/****************************************************************************
-check if a snum is in use
-****************************************************************************/
-BOOL conn_snum_used(struct smbsrv_connection *smb_conn, int snum)
-{
-       struct smbsrv_tcon *tcon;
-       for (tcon=smb_conn->tree.tcons;tcon;tcon=tcon->next) {
-               if (tcon->service == snum) {
-                       return(True);
-               }
-       }
-       return(False);
-}
-
-
 /****************************************************************************
 find a tcon given a cnum
 ****************************************************************************/
 struct smbsrv_tcon *conn_find(struct smbsrv_connection *smb_conn, uint_t cnum)
 {
-       int count=0;
-       struct smbsrv_tcon *tcon;
-
-       for (tcon=smb_conn->tree.tcons;tcon;tcon=tcon->next,count++) {
-               if (tcon->cnum == cnum) {
-                       if (count > 10) {
-                               DLIST_PROMOTE(smb_conn->tree.tcons, tcon);
-                       }
-                       return tcon;
-               }
-       }
-
-       return NULL;
+       return idr_find(smb_conn->tree.idtree_tid, cnum);
 }
 
+/*
+  destroy a connection structure
+*/
+static int conn_destructor(void *ptr)
+{
+       struct smbsrv_tcon *tcon = ptr;
+       idr_remove(tcon->smb_conn->tree.idtree_tid, tcon->cnum);
+       DLIST_REMOVE(tcon->smb_conn->tree.tcons, tcon);
+       return 0;
+}
 
-/****************************************************************************
-  find first available connection slot, starting from a random position.
-The randomisation stops problems with the server dieing and clients
-thinking the server is still available.
-****************************************************************************/
+/*
+  find first available connection slot
+*/
 struct smbsrv_tcon *conn_new(struct smbsrv_connection *smb_conn)
 {
        struct smbsrv_tcon *tcon;
        int i;
 
-       i = bitmap_find(smb_conn->tree.bmap, 1);
-       
+       tcon = talloc_zero_p(smb_conn, struct smbsrv_tcon);
+       if (!tcon) return NULL;
+
+       i = idr_get_new(smb_conn->tree.idtree_tid, tcon, MAX_CONNECTIONS);      
        if (i == -1) {
                DEBUG(1,("ERROR! Out of connection structures\n"));            
                return NULL;
        }
 
-       tcon = talloc_p(smb_conn, struct smbsrv_tcon);
-       if (!tcon) return NULL;
-
-       ZERO_STRUCTP(tcon);
-
        tcon->cnum = i;
        tcon->smb_conn = smb_conn;
 
-       bitmap_set(smb_conn->tree.bmap, i);
-
-       smb_conn->tree.num_open++;
+       talloc_set_destructor(tcon, conn_destructor);
 
        DLIST_ADD(smb_conn->tree.tcons, tcon);
 
@@ -118,36 +94,11 @@ void conn_close_all(struct smbsrv_connection *smb_conn)
 }
 
 
-#if REWRITE_REMOVED
-/****************************************************************************
-clear a vuid out of the validity cache, and as the 'owner' of a connection.
-****************************************************************************/
-void conn_clear_vuid_cache(struct smbsrv_connection *smb_conn, uint16_t vuid)
-{
-       struct smbsrv_tcon *tcon;
-       uint_t i;
-
-       for (tcon=smb_conn->tree.tcons;tcon;tcon=tcon->next) {
-               for (i=0;i<tcon->vuid_cache.entries && i< VUID_CACHE_SIZE;i++) {
-                       if (tcon->vuid_cache.list[i] == vuid) {
-                               tcon->vuid_cache.list[i] = UID_FIELD_INVALID;
-                       }
-               }
-       }
-}
-#endif
-
 /****************************************************************************
  Free a tcon structure.
 ****************************************************************************/
-
 void conn_free(struct smbsrv_connection *smb_conn, struct smbsrv_tcon *tcon)
 {
-       DLIST_REMOVE(smb_conn->tree.tcons, tcon);
-
-       bitmap_clear(smb_conn->tree.bmap, tcon->cnum);
-       smb_conn->tree.num_open--;
-
-       talloc_destroy(tcon);
+       talloc_free(tcon);
 }
 
index c40633eb06270ade0374675bb81cc59668352aeb..6b0994687c07998a03c9535642ccc6140c381b4f 100644 (file)
@@ -215,11 +215,11 @@ struct smbsrv_connection {
 
        /* the context associated with open tree connects on a smb socket */
        struct {
+               /* list of open tree connects */
                struct smbsrv_tcon *tcons;
 
-               /* number of open connections */
-               struct bitmap *bmap;
-               int num_open;
+               /* an id tree used to allocate tids */
+               void *idtree_tid;
        } tree;
 
        /* the context associated with open files on an smb socket */
index 3391a2d3e1b6125ad9fc2a70564352f6d39146de..03542bf4e9c73e20399af98fe4e14c4e1ddb6f7c 100644 (file)
@@ -90,10 +90,6 @@ BOOL reload_services(struct smbsrv_connection *smb, BOOL test)
        if (test && !lp_file_list_changed())
                return(True);
 
-       if (smb) {
-               lp_killunused(smb, conn_snum_used);
-       }
-       
        ret = lp_load(dyn_CONFIGFILE, False, False, True);
 
        /* perhaps the config filename is now set */
index 6975d009a53b09adf65a0c3c11fb2e1b21497fd5..eb2acd3481bc218f36062f4708d796480519d5ff 100644 (file)
@@ -438,8 +438,6 @@ BOOL reload_services(BOOL test)
        if (test && !lp_file_list_changed())
                return(True);
 
-       lp_killunused(conn_snum_used);
-       
        ret = lp_load(dyn_CONFIGFILE, False, False, True);
 
        load_printers();