diff options
author | Andrew Tridgell <tridge@samba.org> | 2001-05-15 00:53:15 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2001-05-15 00:53:15 +0000 |
commit | 8410ef028a5eefb257346b6023a0e96c3cca1012 (patch) | |
tree | c3385a66d02bc391654e3a63f6f8321a2671924c | |
parent | bc51512aadc705cbe5c4d666b7d45271e60d3f00 (diff) | |
download | samba-8410ef028a5eefb257346b6023a0e96c3cca1012.tar.gz samba-8410ef028a5eefb257346b6023a0e96c3cca1012.tar.bz2 samba-8410ef028a5eefb257346b6023a0e96c3cca1012.zip |
make the max_connections code less horrendously inefficient
- it didn't honour the clear flag
- it locked the database (not necessary)
the previous code would do 10^6 kill() operations for 1000 people
logging in - and all with the database locked. Not very scalable.
Still haven't added the counter, that would make it really efficient
(This used to be commit 6bdbeb4a32e52fb05328dcf38dbb90780e1761ef)
-rw-r--r-- | source3/smbd/connection.c | 32 |
1 files changed, 9 insertions, 23 deletions
diff --git a/source3/smbd/connection.c b/source3/smbd/connection.c index 4a9d202fef..47579fa5f7 100644 --- a/source3/smbd/connection.c +++ b/source3/smbd/connection.c @@ -67,6 +67,7 @@ struct count_stat { pid_t mypid; int curr_connections; char *name; + BOOL Clear; }; /**************************************************************************** @@ -80,11 +81,11 @@ static int count_fn( TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *u memcpy(&crec, dbuf.dptr, sizeof(crec)); - if (crec.cnum == -1) + if (crec.cnum == -1) return 0; /* if the pid was not found delete the entry from connections.tdb */ - if (!process_exists(crec.pid) && (errno == ESRCH)) { + if (cs->Clear && !process_exists(crec.pid)) { DEBUG(2,("pid %u doesn't exist - deleting connections %d [%s]\n", (unsigned int)crec.pid, crec.cnum, crec.name)); tdb_delete(the_tdb, kbuf); @@ -106,8 +107,6 @@ BOOL claim_connection(connection_struct *conn,char *name,int max_connections,BOO struct connections_key key; struct connections_data crec; TDB_DATA kbuf, dbuf; - BOOL db_locked = False; - BOOL ret = True; if (!tdb) { tdb = tdb_open(lock_path("connections.tdb"), 0, TDB_CLEAR_IF_FIRST, @@ -126,28 +125,20 @@ BOOL claim_connection(connection_struct *conn,char *name,int max_connections,BOO cs.mypid = sys_getpid(); cs.curr_connections = 0; cs.name = lp_servicename(SNUM(conn)); + cs.Clear = Clear; /* - * Go through and count the connections with the db locked. This is - * slow but essentially what 2.0.x did. JRA. + * Go through and count the connections */ - - if (tdb_lockall(tdb)) - return False; - - db_locked = True; - if (tdb_traverse(tdb, count_fn, &cs) == -1) { DEBUG(0,("claim_connection: traverse of connections.tdb failed.\n")); - ret = False; - goto out; + return False; } if (cs.curr_connections >= max_connections) { DEBUG(1,("claim_connection: Max connections (%d) exceeded for %s\n", max_connections, name )); - ret = False; - goto out; + return False; } } @@ -182,14 +173,9 @@ BOOL claim_connection(connection_struct *conn,char *name,int max_connections,BOO dbuf.dsize = sizeof(crec); if (tdb_store(tdb, kbuf, dbuf, TDB_REPLACE) != 0) - ret = False; - - out: - - if (db_locked) - tdb_unlockall(tdb); + return False; - return ret; + return True; } #if 0 |