PERFORCE change 127286 for review
Fredrik Lindberg
fli at FreeBSD.org
Sun Oct 7 11:18:23 PDT 2007
http://perforce.freebsd.org/chv.cgi?CH=127286
Change 127286 by fli at fli_genesis on 2007/10/07 18:17:44
- Keep track of active probe/annonuce contexts so that
we are able to properly destroy them if the underlying
interface disappears.
- Fix simultanesous probe tie-breaking which was broken.
- Nuke stale code (that was #if 0:oed out)
Affected files ...
.. //depot/projects/soc2007/fli-mdns_sd/mdnsd/dbrec.c#10 edit
.. //depot/projects/soc2007/fli-mdns_sd/mdnsd/dbrec.h#6 edit
Differences ...
==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/dbrec.c#10 (text+ko) ====
@@ -72,6 +72,7 @@
if (error != 0)
goto dbr_init_fail;
TAILQ_INIT(&dbr->dbr_ilist);
+ TAILQ_INIT(&dbr->dbr_paclist);
MDNS_INIT_SET(dbr, dbr_magic);
var_init(&dbr->dbr_vars, mif->mif_glob->g_evl, dbr);
@@ -95,11 +96,16 @@
{
struct md_if *mif;
struct dbr_ident *dbi, *dbi2;
+ struct dbr_pac *pac, *pac2;
MDNS_INIT_ASSERT(dbr, dbr_magic);
RW_WLOCK(dbr, dbr_lock);
mif = dbr->dbr_ctx;
+ TAILQ_FOREACH_SAFE(pac, &dbr->dbr_paclist, pac_next, pac2) {
+ dbr_pac_destroy(pac);
+ }
+
TAILQ_FOREACH_SAFE(dbi, &dbr->dbr_ilist, dbi_next, dbi2) {
ident_del(dbr, dbi);
}
@@ -207,12 +213,6 @@
res_update(dir, names, vtd_len);
}
free(names);
-
-#if 0
- dprintf(DEBUG_DBR,
- "Database record r=%x, (%ls) updated, flags=%x, clones=%d",
- dr, dr->dr_names[dr->dr_cur], dr->dr_flags, dr->dr_clones);
-#endif
}
/*
@@ -1172,45 +1172,6 @@
ds = ds2;
}
}
-
-#if 0
- TAILQ_FOREACH(ds, &dsh->ds_clone.head, ds_clone.next) {
- if (i == dsh->ds_clones || i == reslen)
- break;
- if (ds->ds_data != NULL)
- free(ds->ds_data);
- ds->ds_data = _wcsdup(res[i]);
-
- p = mdns_res_encode(dir->dir_class, dir->dir_type, res[i],
- MDNS_ENC_WCHAR, wcslen(res[i]), &rlen);
- if (p == NULL) {
- dprintf(DEBUG_DBR, "Failed to encode resource");
- continue;
- }
- error = record_res_setdata(&ds->ds_res, REC_RESOWN, p, rlen);
- if (error != 0) {
-
- }
- i++;
- }
-
- /* More results than clones, expand */
- if (reslen > i) {
- diff = reslen - i;
- while (diff-- > 0) {
- res_add(dr, dir, dsh, res[i]);
- i++;
- }
- }
- /* More clones than results, shrink */
- else if (dsh->ds_clones >= i) {
- diff = dsh->ds_clones - i;
- while (diff-- >= 0) {
- ds = TAILQ_LAST(&dsh->ds_clone.head, clone_head);
- res_del(ds);
- }
- }
-#endif
}
/*
@@ -1653,6 +1614,7 @@
if (prc == NULL)
return;
+ prt = record_type_first(prc);
if (prt == NULL)
return;
@@ -1710,6 +1672,12 @@
else if (rr->rr_len > prr->rr_len)
outcome = 2;
}
+
+ if (outcome != 0)
+ break;
+
+ rr = record_res_next(rr);
+ prr = record_res_next(prr);
}
if (prr != NULL && rr == NULL)
outcome = 1;
@@ -1724,6 +1692,9 @@
}
if (outcome != 0)
break;
+
+ rc = record_class_next(rc);
+ prc = record_class_next(prc);
}
/*
@@ -1740,13 +1711,16 @@
else if (prt == NULL && rt != NULL)
outcome = 2;
+
if (outcome == 0) {
dprintf(DEBUG_DBR, "Tie after tie-breaking on %ls, "
"records should be equal", dr->dr_name);
}
if (outcome == 1) {
dprintf(DEBUG_DBR, "Lost tie-breaking on %ls", dr->dr_name);
+ RW_WLOCK(dbr, dbr_lock);
col_probe(dr);
+ RW_UNLOCK(dbr, dbr_lock);
}
else if (outcome == 2) {
dprintf(DEBUG_DBR, "Won tie-breaking on %ls", dr->dr_name);
@@ -1831,7 +1805,7 @@
struct dbr_rec *dr;
struct record *r;
- RW_RLOCK(dbr, dbr_lock);
+ RW_WLOCK(dbr, dbr_lock);
pac = dbr_pac_new(dbr, PAC_PROBE);
records_foreach(r, &dbr->dbr_recs) {
dr = record_getparent(r);
@@ -1861,6 +1835,7 @@
TAILQ_INIT(&pac->pac_head);
MDNS_INIT_SET(pac, pac_magic);
MTX_INIT(pac, pac_mtx, NULL);
+ TAILQ_INSERT_TAIL(&dbr->dbr_paclist, pac, pac_next);
dprintf(DEBUG_DBR, "Created probe/announce context pac=%x", pac);
return (pac);
@@ -1892,6 +1867,7 @@
dr->dr_flags &= ~(DR_PROBING | DR_ANNOUNCE);
dr->dr_pac = NULL;
}
+ TAILQ_REMOVE(&dbr->dbr_paclist, pac, pac_next);
dprintf(DEBUG_DBR, "Destroyed probe/announce context pac=%x", pac);
MTX_UNLOCK(pac, pac_mtx);
MTX_DESTROY(pac, pac_mtx);
@@ -2158,13 +2134,13 @@
mif = dbr->dbr_ctx;
MDNS_INIT_ASSERT(mif, mif_magic);
- RW_RLOCK(dbr, dbr_lock);
/*
* If this is the last step we create an announce context
* and add all valid records to it.
*/
if (pac->pac_step == 3) {
+ RW_WLOCK(dbr, dbr_lock);
pac_an = dbr_pac_new(dbr, PAC_ANNOUNCE);
TAILQ_FOREACH_SAFE(dr, &pac->pac_head, dr_pac_next, dr2) {
dbr_probe_del(dr);
@@ -2189,6 +2165,8 @@
mdns_pkg_sethdr(&pc6, 0, MDNS_HEAD_QUERY | MDNS_HEAD_AA);
#endif
+ RW_RLOCK(dbr, dbr_lock);
+
/*
* Add all valid records to the packet chain
*/
==== //depot/projects/soc2007/fli-mdns_sd/mdnsd/dbrec.h#6 (text+ko) ====
@@ -38,6 +38,7 @@
* Database record set
*/
struct dbr_ident;
+struct dbr_pac;
struct dbr {
MAGIC(dbr_magic);
DEF_MTX(dbr_mtx);
@@ -47,6 +48,7 @@
struct vars dbr_vars; /* Variable subsystem */
struct hashtbl dbr_ident; /* Identifier lookup */
TAILQ_HEAD(, dbr_ident) dbr_ilist; /* Identifier list */
+ TAILQ_HEAD(, dbr_pac) dbr_paclist; /* Active probe/annonuce contexs */
};
/*
@@ -122,7 +124,6 @@
/*
* Database record resource name
*/
-struct dbr_pac;
struct dbr_res;
struct dbr_rec {
struct record dr_rec;
@@ -185,6 +186,7 @@
#define PAC_PROBE 0x02 /* This is a probe context */
#define PAC_ANNOUNCE 0x04 /* This is an announce context */
TAILQ_HEAD(, dbr_rec) pac_head;
+ TAILQ_ENTRY(dbr_pac) pac_next;
};
/* Initialize record database */
More information about the p4-projects
mailing list