PERFORCE change 109852 for review
Michael Bushkov
bushman at FreeBSD.org
Mon Nov 13 15:13:28 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=109852
Change 109852 by bushman at bushman_nss_ldap_cached on 2006/11/13 14:53:56
+ hashtable.h updated
+ configuration_entry->flags field added (1 int insted of 3)
Affected files ...
.. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/cached.c#8 edit
.. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/cachelib.c#5 edit
.. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/config.c#5 edit
.. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/config.h#5 edit
.. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/hashtable.h#5 edit
.. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/mp_rs_query.c#6 edit
.. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/mp_ws_query.c#5 edit
.. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/parser.c#5 edit
.. //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/query.c#6 edit
Differences ...
==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/cached.c#8 (text) ====
@@ -308,7 +308,7 @@
entries_size = configuration_get_entries_size(config);
for (i = 0; i < entries_size; ++i) {
entry = configuration_get_entry(config, i);
- if (entry->precache & PRECACHING_ENABLED) {
+ if (entry->flags & CONFIG_ENTRY_PRECACHING_ENABLED_FLAG) {
mp_agent = (struct multipart_agent *)find_agent(
s_agent_table, entry->name, MULTIPART_AGENT);
==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/cachelib.c#5 (text) ====
@@ -593,7 +593,8 @@
HASHTABLE_INIT(&(new_common_entry->items),
struct cache_ht_item_data_, data,
- new_common_entry->common_params.cache_entries_size);
+ new_common_entry->common_params.cache_entries_size,
+ HASHTABLE_INITIAL_ENTRIES_CAPACITY);
if (!HASHTABLE_OK(&(new_common_entry->items))) {
free(new_common_entry->common_params.entry_name);
==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/config.c#5 (text) ====
@@ -70,8 +70,8 @@
TRACE_IN(check_configuration_entry);
retval = 0;
- if ((entry->precache & PRECACHING_ENABLED) &&
- (entry->perform_actual_lookups == 0)) {
+ if ((entry->flags & CONFIG_ENTRY_PRECACHING_ENABLED_FLAG) &&
+ !(entry->flags & CONFIG_ENTRY_PERFORM_ACTUAL_LOOKUPS_FLAG)) {
LOG_ERR_2("check_configuration_entry",
"precaching for '%s' can't be done without "
"perform_actual_lookups turned on", entry->name);
==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/config.h#5 (text) ====
@@ -57,8 +57,11 @@
#define DEFAULT_MULITPART_SESSIONS_SIZE (1024)
#define DEFAULT_MULITPART_LIFETIME (3600)
-#define PRECACHING_ENABLED (1)
-#define PRECACHING_NO_AUTO_FLUSH (1 << 1)
+#define CONFIG_ENTRY_DISABLED_FLAG (1)
+#define CONFIG_ENTRY_PERFORM_ACTUAL_LOOKUPS_FLAG (1 << 1)
+#define CONFIG_ENTRY_PRECACHING_ENABLED_FLAG (1 << 2)
+#define CONFIG_ENTRY_PRECACHING_NO_AUTO_FLUSH_FLAG (1 << 3)
+
extern const char *c_default_entries[6];
@@ -93,9 +96,7 @@
pthread_mutex_t negative_cache_lock;
pthread_mutex_t mp_cache_lock;
- int perform_actual_lookups;
- int precache;
- int enabled;
+ int flags;
};
/*
==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/hashtable.h#5 (text) ====
@@ -38,7 +38,7 @@
/*
* This file contains queue.h-like macro definitions for hash tables.
* Hash table is organized as an array of the specified size of the user
- * defined (with HASTABLE_ENTRY_HEAD) structures. Each hash table
+ * defined (with HASHTABLE_ENTRY_HEAD) structures. Each hash table
* entry (user defined structure) stores its elements in the sorted array.
* You can place elements into the hash table, retrieve elements with
* specified key, traverse through all elements, and delete them.
@@ -72,7 +72,7 @@
* Unlike most of queue.h data types, hash tables can not be initialized
* statically - so there is no HASHTABLE_HEAD_INITIALIZED macro.
*/
-#define HASHTABLE_INIT(table, type, field, _entries_size) \
+#define HASHTABLE_INIT(table, type, field, _entries_size, in_ent_cap) \
do { \
hashtable_index_t var; \
(table)->entries = malloc(sizeof(*(table)->entries) * \
@@ -83,14 +83,13 @@
(table)->entries_size = (_entries_size); \
for (var = 0; var < HASHTABLE_ENTRIES_COUNT(table); ++var) {\
(table)->entries[var].field.capacity = \
- HASHTABLE_INITIAL_ENTRIES_CAPACITY; \
+ in_ent_cap; \
(table)->entries[var].field.size = 0; \
(table)->entries[var].field.values = malloc( \
sizeof(type) * \
- HASHTABLE_INITIAL_ENTRIES_CAPACITY); \
+ in_ent_cap); \
if ((table)->entries[var].field.values == NULL) {\
HASHTABLE_DESTROY(table, field); \
- (table)->entries = NULL; \
break; \
} \
} \
@@ -105,9 +104,10 @@
#define HASHTABLE_DESTROY(table, field) \
do { \
hashtable_index_t var; \
- for (var = 0; var < HASHTABLE_ENTRIES_COUNT(table); ++var) {\
+ for (var = 0; var < HASHTABLE_ENTRIES_COUNT(table); ++var)\
free((table)->entries[var].field.values); \
- } \
+ free((table)->entries); \
+ (table)->entries = NULL; \
} while (0)
#define HASHTABLE_GET_ENTRY(table, hash) (&((table)->entries[hash]))
@@ -138,25 +138,32 @@
((entry)->field.capacity)
#define HASHTABLE_ENTRY_CAPACITY_INCREASE(entry, field, type) \
- (entry)->field.capacity *= 2; \
- (entry)->field.values = (type *)realloc((entry)->field.values, \
- (entry)->field.capacity * sizeof(type));
+ do { \
+ (entry)->field.capacity *= 2; \
+ (entry)->field.values = (type *)realloc((entry)->field.values,\
+ (entry)->field.capacity * sizeof(type)); \
+ } while (0) \
#define HASHTABLE_ENTRY_CAPACITY_DECREASE(entry, field, type) \
- (entry)->field.capacity /= 2; \
- (entry)->field.values = (type *)realloc((entry)->field.values, \
- (entry)->field.capacity * sizeof(type));
+ do { \
+ (entry)->field.capacity /= 2; \
+ (entry)->field.values = (type *)realloc((entry)->field.values,\
+ (entry)->field.capacity * sizeof(type)); \
+ } while (0)
+
+#define HASHTABLE_ENTRY_CAPACITY_OP_OK(entry, field) \
+ ((entry)->field.values != NULL)
/*
* Generates prototypes for the hash table functions
*/
#define HASHTABLE_PROTOTYPE(name, entry_, type) \
hashtable_index_t name##_CALCULATE_HASH(struct name *, type *); \
-void name##_ENTRY_STORE(struct entry_*, type *); \
+int name##_ENTRY_STORE(struct entry_*, type *); \
type *name##_ENTRY_FIND(struct entry_*, type *); \
type *name##_ENTRY_FIND_SPECIAL(struct entry_ *, type *, \
int (*) (const void *, const void *)); \
-void name##_ENTRY_REMOVE(struct entry_*, type *);
+int name##_ENTRY_REMOVE(struct entry_*, type *);
/*
* Generates implementations of the hash table functions
@@ -168,17 +175,21 @@
return HASH(data, table->entries_size); \
} \
\
-void name##_ENTRY_STORE(struct entry_ *the_entry, type *data) \
+int name##_ENTRY_STORE(struct entry_ *the_entry, type *data) \
{ \
\
- if (the_entry->field.size == the_entry->field.capacity) \
+ if (the_entry->field.size == the_entry->field.capacity) { \
HASHTABLE_ENTRY_CAPACITY_INCREASE(the_entry, field, type);\
+ if (!HASHTABLE_ENTRY_CAPACITY_OP_OK(the_entry, field)) \
+ return (-1); \
+ } \
\
memcpy(&(the_entry->field.values[the_entry->field.size++]), \
- data, \
- sizeof(type)); \
+ data, sizeof(type)); \
qsort(the_entry->field.values, the_entry->field.size, \
sizeof(type), CMP); \
+ \
+ return (0); \
} \
\
type *name##_ENTRY_FIND(struct entry_ *the_entry, type *key) \
@@ -191,16 +202,18 @@
type *name##_ENTRY_FIND_SPECIAL(struct entry_ *the_entry, type *key, \
int (*compar) (const void *, const void *)) \
{ \
+ \
return ((type *)bsearch(key, the_entry->field.values, \
the_entry->field.size, sizeof(type), compar)); \
} \
\
-void name##_ENTRY_REMOVE(struct entry_ *the_entry, type *del_elm) \
+int name##_ENTRY_REMOVE(struct entry_ *the_entry, type *del_elm) \
{ \
\
memmove(del_elm, del_elm + 1, \
(&the_entry->field.values[--the_entry->field.size] - del_elm) *\
sizeof(type)); \
+ return (0); \
}
/*
==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/mp_rs_query.c#6 (text) ====
@@ -189,7 +189,7 @@
goto fin;
}
- if (qstate->config_entry->enabled == 0) {
+ if (qstate->config_entry->flags & CONFIG_ENTRY_DISABLED_FLAG) {
c_mp_rs_response->error_code = EACCES;
LOG_ERR_2("read_session_request",
@@ -198,7 +198,8 @@
goto fin;
}
- if (qstate->config_entry->perform_actual_lookups != 0)
+ if (qstate->config_entry->flags &
+ CONFIG_ENTRY_PERFORM_ACTUAL_LOOKUPS_FLAG)
dec_cache_entry_name = strdup(
qstate->config_entry->mp_cache_params.entry_name);
else {
@@ -223,7 +224,8 @@
configuration_unlock(s_configuration);
if ((c_entry == INVALID_CACHE) &&
- (qstate->config_entry->perform_actual_lookups != 0))
+ (qstate->config_entry->flags &
+ CONFIG_ENTRY_PERFORM_ACTUAL_LOOKUPS_FLAG))
c_entry = register_new_mp_cache_entry(qstate,
dec_cache_entry_name);
@@ -236,7 +238,8 @@
CELT_MULTIPART);
if ((rs == INVALID_CACHE_MP_READ_SESSION) &&
- (qstate->config_entry->perform_actual_lookups != 0)) {
+ (qstate->config_entry->flags &
+ CONFIG_ENTRY_PERFORM_ACTUAL_LOOKUPS_FLAG)) {
lookup_agent = find_agent(s_agent_table,
c_mp_rs_request->entry, MULTIPART_AGENT);
==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/mp_ws_query.c#5 (text) ====
@@ -188,7 +188,7 @@
goto fin;
}
- if (qstate->config_entry->enabled == 0) {
+ if (qstate->config_entry->flags & CONFIG_ENTRY_DISABLED_FLAG) {
c_mp_ws_response->error_code = EACCES;
LOG_ERR_2("write_session_request",
@@ -197,7 +197,8 @@
goto fin;
}
- if (qstate->config_entry->perform_actual_lookups != 0) {
+ if (qstate->config_entry->flags &
+ CONFIG_ENTRY_PERFORM_ACTUAL_LOOKUPS_FLAG) {
c_mp_ws_response->error_code = EOPNOTSUPP;
LOG_ERR_2("write_session_request",
==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/parser.c#5 (text) ====
@@ -43,6 +43,7 @@
static enum cache_policy_t get_policy(const char *);
static int get_yesno(const char *);
static int check_cachename(const char *);
+static void set_check_files(struct configuration *, const char *, int);
static void set_keep_hot_count(struct configuration *, const char *, int);
static void set_negative_policy(struct configuration *, const char *,
enum cache_policy_t);
@@ -125,12 +126,28 @@
TRACE_IN(enable_cache);
entry = find_create_entry(config, entry_name);
- if (entry != NULL)
- entry->enabled = flag;
+ if (entry != NULL) {
+ if (flag != 0)
+ entry->flags &= ~CONFIG_ENTRY_DISABLED_FLAG;
+ else
+ entry->flags |= CONFIG_ENTRY_DISABLED_FLAG;
+ }
TRACE_OUT(enable_cache);
}
static void
+set_check_files(struct configuration *config, const char *entry_name, int flag)
+{
+ struct configuration_entry *entry;
+
+ TRACE_IN(set_check_files);
+ entry = find_create_entry(config, entry_name);
+// if (entry != NULL)
+// entry->check_files = flag;
+ TRACE_OUT(set_check_files);
+}
+
+static void
set_positive_time_to_live(struct configuration *config,
const char *entry_name, int ttl)
{
@@ -172,9 +189,9 @@
}
if (flag != 0)
- entry->precache |= PRECACHING_ENABLED;
+ entry->flags |= CONFIG_ENTRY_PRECACHING_ENABLED_FLAG;
else
- entry->precache &= ~PRECACHING_ENABLED;
+ entry->flags &= ~CONFIG_ENTRY_PRECACHING_ENABLED_FLAG;
TRACE_OUT(set_precaching);
}
@@ -195,9 +212,9 @@
return;
}
if (flag != 0)
- entry->precache |= PRECACHING_NO_AUTO_FLUSH;
+ entry->flags |= CONFIG_ENTRY_PRECACHING_NO_AUTO_FLUSH_FLAG;
else
- entry->precache &= ~PRECACHING_NO_AUTO_FLUSH;
+ entry->flags &= ~CONFIG_ENTRY_PRECACHING_NO_AUTO_FLUSH_FLAG;
TRACE_OUT(set_precaching);
}
@@ -210,7 +227,7 @@
struct timeval lifetime;
TRACE_IN(set_negative_time_to_live);
- assert(nttl > 0);
+ assert(nttl >= 0);
assert(entry_name != NULL);
memset(&lifetime, 0, sizeof(struct timeval));
lifetime.tv_sec = nttl;
@@ -294,8 +311,14 @@
assert(entry_name != NULL);
entry = find_create_entry(config, entry_name);
- if (entry != NULL)
- entry->perform_actual_lookups = flag;
+ if (entry != NULL) {
+ if (flag != 0)
+ entry->flags |=
+ CONFIG_ENTRY_PERFORM_ACTUAL_LOOKUPS_FLAG;
+ else
+ entry->flags &=
+ ~CONFIG_ENTRY_PERFORM_ACTUAL_LOOKUPS_FLAG;
+ }
TRACE_OUT(set_perform_actual_lookups);
}
@@ -324,9 +347,9 @@
get_yesno(const char *str)
{
- if (strcmp(str, "yes") == 0)
+ if (strcasecmp(str, "yes") == 0)
return (1);
- else if (strcmp(str, "no") == 0)
+ else if (strcasecmp(str, "no") == 0)
return (0);
else
return (-1);
@@ -357,11 +380,11 @@
get_policy(const char *str)
{
- if (strcmp(str, "fifo") == 0)
+ if (strcasecmp(str, "fifo") == 0)
return (CPT_FIFO);
- else if (strcmp(str, "lru") == 0)
+ else if (strcasecmp(str, "lru") == 0)
return (CPT_LRU);
- else if (strcmp(str, "lfu") == 0)
+ else if (strcasecmp(str, "lfu") == 0)
return (CPT_LFU);
return (-1);
@@ -421,9 +444,18 @@
case '#':
case '\0':
continue;
+ case 'c':
+ if ((field_count == 3) &&
+ (strcasecmp(fields[0], "check-files") == 0) &&
+ (check_cachename(fields[1]) == 0) &&
+ ((value = get_yesno(fields[2])) != -1)) {
+ set_check_files(config, fields[1], value);
+ continue;
+ }
+ break;
case 'e':
if ((field_count == 3) &&
- (strcmp(fields[0], "enable-cache") == 0) &&
+ (strcasecmp(fields[0], "enable-cache") == 0) &&
(check_cachename(fields[1]) == 0) &&
((value = get_yesno(fields[2])) != -1)) {
enable_cache(config, fields[1], value);
@@ -432,40 +464,40 @@
break;
case 'd':
if ((field_count == 2) &&
- (strcmp(fields[0], "debug-level") == 0) &&
+ (strcasecmp(fields[0], "debug-level") == 0) &&
((value = get_number(fields[1], 0, 10)) != -1)) {
continue;
}
break;
case 'p':
if ((field_count == 3) &&
- (strcmp(fields[0], "positive-time-to-live") == 0) &&
+ (strcasecmp(fields[0], "positive-time-to-live") == 0) &&
(check_cachename(fields[1]) == 0) &&
((value = get_number(fields[2], 0, -1)) != -1)) {
set_positive_time_to_live(config,
fields[1], value);
continue;
} else if ((field_count == 3) &&
- (strcmp(fields[0], "positive-policy") == 0) &&
+ (strcasecmp(fields[0], "positive-policy") == 0) &&
(check_cachename(fields[1]) == 0) &&
((value = get_policy(fields[2])) != -1)) {
set_positive_policy(config, fields[1], value);
continue;
} else if ((field_count == 3) &&
- (strcmp(fields[0], "perform-actual-lookups") == 0) &&
+ (strcasecmp(fields[0], "perform-actual-lookups") == 0) &&
(check_cachename(fields[1]) == 0) &&
((value = get_yesno(fields[2])) != -1)) {
set_perform_actual_lookups(config, fields[1],
value);
continue;
} else if ((field_count == 3) &&
- (strcmp(fields[0], "precache") == 0) &&
+ (strcasecmp(fields[0], "precache") == 0) &&
(check_cachename(fields[1]) == 0) &&
((value = get_yesno(fields[2])) != -1)) {
set_precache(config, fields[1], value);
continue;
} else if ((field_count == 3) &&
- (strcmp(fields[0], "precache-no-auto-flush") == 0) &&
+ (strcasecmp(fields[0], "precache-no-auto-flush") == 0) &&
(check_cachename(fields[1]) == 0) &&
((value = get_yesno(fields[2])) != -1)) {
set_precache_no_auto_flush(config, fields[1],
@@ -475,14 +507,14 @@
break;
case 'n':
if ((field_count == 3) &&
- (strcmp(fields[0], "negative-time-to-live") == 0) &&
+ (strcasecmp(fields[0], "negative-time-to-live") == 0) &&
(check_cachename(fields[1]) == 0) &&
((value = get_number(fields[2], 0, -1)) != -1)) {
set_negative_time_to_live(config,
fields[1], value);
continue;
} else if ((field_count == 3) &&
- (strcmp(fields[0], "negative-policy") == 0) &&
+ (strcasecmp(fields[0], "negative-policy") == 0) &&
(check_cachename(fields[1]) == 0) &&
((value = get_policy(fields[2])) != -1)) {
set_negative_policy(config,
@@ -492,7 +524,7 @@
break;
case 's':
if ((field_count == 3) &&
- (strcmp(fields[0], "suggested-size") == 0) &&
+ (strcasecmp(fields[0], "suggested-size") == 0) &&
(check_cachename(fields[1]) == 0) &&
((value = get_number(fields[2], 1, -1)) != -1)) {
set_suggested_size(config, fields[1], value);
@@ -501,7 +533,7 @@
break;
case 't':
if ((field_count == 2) &&
- (strcmp(fields[0], "threads") == 0) &&
+ (strcasecmp(fields[0], "threads") == 0) &&
((value = get_number(fields[1], 1, -1)) != -1)) {
set_threads_num(config, value);
continue;
@@ -509,7 +541,7 @@
break;
case 'k':
if ((field_count == 3) &&
- (strcmp(fields[0], "keep-hot-count") == 0) &&
+ (strcasecmp(fields[0], "keep-hot-count") == 0) &&
(check_cachename(fields[1]) == 0) &&
((value = get_number(fields[2], 0, -1)) != -1)) {
set_keep_hot_count(config,
==== //depot/projects/soc2006/nss_ldap_cached/src/usr.sbin/cached/query.c#6 (text) ====
@@ -427,7 +427,7 @@
goto fin;
}
- if (qstate->config_entry->enabled == 0) {
+ if (qstate->config_entry->flags & CONFIG_ENTRY_DISABLED_FLAG) {
write_response->error_code = EACCES;
LOG_ERR_2("write_request",
@@ -436,7 +436,8 @@
goto fin;
}
- if (qstate->config_entry->perform_actual_lookups != 0) {
+ if (qstate->config_entry->flags &
+ CONFIG_ENTRY_PERFORM_ACTUAL_LOOKUPS_FLAG) {
write_response->error_code = EOPNOTSUPP;
LOG_ERR_2("write_request",
@@ -501,7 +502,7 @@
goto fin;
}
- if (qstate->config_entry->enabled == 0) {
+ if (qstate->config_entry->flags & CONFIG_ENTRY_DISABLED_FLAG) {
write_response->error_code = EACCES;
LOG_ERR_2("negative_write_request",
@@ -510,7 +511,8 @@
goto fin;
}
- if (qstate->config_entry->perform_actual_lookups != 0) {
+ if (qstate->config_entry->flags &
+ CONFIG_ENTRY_PERFORM_ACTUAL_LOOKUPS_FLAG) {
write_response->error_code = EOPNOTSUPP;
LOG_ERR_2("negative_write_request",
@@ -700,7 +702,7 @@
goto fin;
}
- if (qstate->config_entry->enabled == 0) {
+ if (qstate->config_entry->flags & CONFIG_ENTRY_DISABLED_FLAG) {
read_response->error_code = EACCES;
LOG_ERR_2("read_request",
@@ -713,7 +715,8 @@
* if we perform lookups by ourselves, then we don't need to separate
* cache entries by euid and egid
*/
- if (qstate->config_entry->perform_actual_lookups != 0)
+ if (qstate->config_entry->flags &
+ CONFIG_ENTRY_PERFORM_ACTUAL_LOOKUPS_FLAG)
memset(read_request->cache_key, 0, qstate->eid_str_length);
else {
#ifdef NS_CACHED_EID_CHECKING
@@ -770,7 +773,8 @@
configuration_unlock_entry(qstate->config_entry, CELT_NEGATIVE);
if ((read_response->error_code == -1) &&
- (qstate->config_entry->perform_actual_lookups != 0)) {
+ (qstate->config_entry->flags &
+ CONFIG_ENTRY_PERFORM_ACTUAL_LOOKUPS_FLAG)) {
free(read_response->data);
read_response->data = NULL;
read_response->data_size = 0;
@@ -1014,7 +1018,8 @@
config_entry = configuration_get_entry(
s_configuration, i);
- if (config_entry->perform_actual_lookups == 0)
+ if (!(config_entry->flags &
+ CONFIG_ENTRY_PERFORM_ACTUAL_LOOKUPS_FLAG))
clear_config_entry_part(config_entry,
qstate->eid_str, qstate->eid_str_length);
}
@@ -1031,7 +1036,8 @@
goto fin;
}
- if (qstate->config_entry->perform_actual_lookups != 0) {
+ if (qstate->config_entry->flags &
+ CONFIG_ENTRY_PERFORM_ACTUAL_LOOKUPS_FLAG) {
LOG_ERR_2("transform_request",
"can't transform the cache entry %s"
", because it ised for actual lookups",
More information about the p4-projects
mailing list