Cleanup patches for notify_trigger
Volker Lendecke
Volker.Lendecke at SerNet.DE
Tue Mar 26 04:14:56 MDT 2013
Hi!
While doing work to tune our notify implementation in the
clustered case, I did some cleanup and streamlining of the
nonclustered notify as well. Please see the attached
patchset.
Thanks,
Volker
--
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de
-------------- next part --------------
From 4fb30f4393d5e25321901bb75cf84228534a2ba1 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 31 Oct 2012 13:02:19 +0100
Subject: [PATCH 1/5] smbd: Avoid some talloc_realloc in notify_internal
For the nonclustered case we will only ever have one vnn in notify_index.tdb.
For this case, without this patch we did talloc_realloc when collecting vnns to
be able to do the memcpy instead of explicit copy with a for-loop. This new
code will partition the new vnns we see when parsing a notify_index.tdb record
into ourselves and all foreign vnns, only really collecting the foreign ones in
an array.
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/smbd/notify_internal.c | 22 ++++++++++++++++------
1 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/source3/smbd/notify_internal.c b/source3/smbd/notify_internal.c
index f5a8584..af838d6 100644
--- a/source3/smbd/notify_internal.c
+++ b/source3/smbd/notify_internal.c
@@ -484,7 +484,7 @@ static void notify_trigger_index_parser(TDB_DATA key, TDB_DATA data,
struct notify_trigger_index_state *state =
(struct notify_trigger_index_state *)private_data;
uint32_t *new_vnns;
- size_t i, num_vnns, num_new_vnns;
+ size_t i, num_vnns, num_new_vnns, num_remote_vnns;
if ((data.dsize % sizeof(uint32_t)) != 0) {
DEBUG(1, ("Invalid record size in notify index db: %u\n",
@@ -493,22 +493,32 @@ static void notify_trigger_index_parser(TDB_DATA key, TDB_DATA data,
}
new_vnns = (uint32_t *)data.dptr;
num_new_vnns = data.dsize / sizeof(uint32_t);
-
- num_vnns = talloc_array_length(state->vnns);
+ num_remote_vnns = num_new_vnns;
for (i=0; i<num_new_vnns; i++) {
if (new_vnns[i] == state->my_vnn) {
state->found_my_vnn = true;
+ num_remote_vnns -= 1;
}
}
+ if (num_remote_vnns == 0) {
+ return;
+ }
+ num_vnns = talloc_array_length(state->vnns);
state->vnns = talloc_realloc(state->mem_ctx, state->vnns, uint32_t,
- num_vnns + num_new_vnns);
- if ((num_vnns + num_new_vnns != 0) && (state->vnns == NULL)) {
+ num_vnns + num_remote_vnns);
+ if (state->vnns == NULL) {
DEBUG(1, ("talloc_realloc failed\n"));
return;
}
- memcpy(&state->vnns[num_vnns], data.dptr, data.dsize);
+
+ for (i=0; i<num_new_vnns; i++) {
+ if (new_vnns[i] != state->my_vnn) {
+ state->vnns[num_vnns] = new_vnns[i];
+ num_vnns += 1;
+ }
+ }
}
static int vnn_cmp(const void *p1, const void *p2)
--
1.7.3.4
From 793831c3454938b3551634fb6fde422047821def Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 31 Oct 2012 13:08:18 +0100
Subject: [PATCH 2/5] smbd: Slightly simplify notify_trigger
This straightens the for-loop walking the path components slightly
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/smbd/notify_internal.c | 11 +++++------
1 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/source3/smbd/notify_internal.c b/source3/smbd/notify_internal.c
index af838d6..ddf8160 100644
--- a/source3/smbd/notify_internal.c
+++ b/source3/smbd/notify_internal.c
@@ -627,6 +627,7 @@ void notify_trigger(struct notify_context *notify,
idx_state.mem_ctx = talloc_tos();
idx_state.vnns = NULL;
+ idx_state.found_my_vnn = false;
idx_state.my_vnn = get_my_vnn();
for (p = strchr(path+1, '/'); p != NULL; p = next_p) {
@@ -636,18 +637,16 @@ void notify_trigger(struct notify_context *notify,
next_p = strchr(p+1, '/');
recursive = (next_p != NULL);
- idx_state.found_my_vnn = false;
-
dbwrap_parse_record(
notify->db_index,
make_tdb_data(discard_const_p(uint8_t, path), path_len),
notify_trigger_index_parser, &idx_state);
- if (!idx_state.found_my_vnn) {
- continue;
+ if (idx_state.found_my_vnn) {
+ notify_trigger_local(notify, action, filter,
+ path, path_len, recursive);
+ idx_state.found_my_vnn = false;
}
- notify_trigger_local(notify, action, filter,
- path, path_len, recursive);
}
ctdbd_conn = messaging_ctdbd_connection();
--
1.7.3.4
From ac44a813276979db54f413e92e22fbd54cf47611 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 31 Oct 2012 13:10:12 +0100
Subject: [PATCH 3/5] smbd: Slightly simplify notify_trigger
We have a good chance that we did not collect any remote vnns. This
avoids trying to walk the remote vnns altogether.
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/smbd/notify_internal.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/source3/smbd/notify_internal.c b/source3/smbd/notify_internal.c
index ddf8160..f3d874d 100644
--- a/source3/smbd/notify_internal.c
+++ b/source3/smbd/notify_internal.c
@@ -649,6 +649,10 @@ void notify_trigger(struct notify_context *notify,
}
}
+ if (idx_state.vnns == NULL) {
+ goto done;
+ }
+
ctdbd_conn = messaging_ctdbd_connection();
if (ctdbd_conn == NULL) {
goto done;
--
1.7.3.4
From d1be93618494e95526bac47a264518aca7bd2333 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 31 Oct 2012 13:11:19 +0100
Subject: [PATCH 4/5] smbd: We don't collect our own vnn anymore
notify_trigger_index_parser will not anymore add ourselves into the vnn
list that it collects.
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/smbd/notify_internal.c | 3 ---
1 files changed, 0 insertions(+), 3 deletions(-)
diff --git a/source3/smbd/notify_internal.c b/source3/smbd/notify_internal.c
index f3d874d..ee6f4cc 100644
--- a/source3/smbd/notify_internal.c
+++ b/source3/smbd/notify_internal.c
@@ -671,9 +671,6 @@ void notify_trigger(struct notify_context *notify,
if (vnn == last_vnn) {
continue;
}
- if (vnn == idx_state.my_vnn) {
- continue;
- }
if ((remote_blob == NULL) &&
!notify_push_remote_blob(
talloc_tos(), action, filter,
--
1.7.3.4
From 1da986f5d8d35f88b43e0aa5144157d548a7c670 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Wed, 31 Oct 2012 13:13:50 +0100
Subject: [PATCH 5/5] smbd: Remove an optimization that became unnecessary
After we only collect nonlocal vnns in idx_state.vnns now, at this point
we *know* we have something to send to a remote node. The previous code
avoided the call to notify_push_remote_blob with an if-statement that
has now become unnecessary.
Signed-off-by: Volker Lendecke <vl at samba.org>
---
source3/smbd/notify_internal.c | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/source3/smbd/notify_internal.c b/source3/smbd/notify_internal.c
index ee6f4cc..2dc8674 100644
--- a/source3/smbd/notify_internal.c
+++ b/source3/smbd/notify_internal.c
@@ -662,7 +662,12 @@ void notify_trigger(struct notify_context *notify,
qsort(idx_state.vnns, num_vnns, sizeof(uint32_t), vnn_cmp);
last_vnn = 0xffffffff;
- remote_blob = NULL;
+
+ if (!notify_push_remote_blob(talloc_tos(), action, filter, path,
+ &remote_blob, &remote_blob_len)) {
+ DEBUG(1, ("notify_push_remote_blob failed\n"));
+ goto done;
+ }
for (i=0; i<num_vnns; i++) {
uint32_t vnn = idx_state.vnns[i];
@@ -671,12 +676,6 @@ void notify_trigger(struct notify_context *notify,
if (vnn == last_vnn) {
continue;
}
- if ((remote_blob == NULL) &&
- !notify_push_remote_blob(
- talloc_tos(), action, filter,
- path, &remote_blob, &remote_blob_len)) {
- break;
- }
status = ctdbd_messaging_send_blob(
ctdbd_conn, vnn, CTDB_SRVID_SAMBA_NOTIFY_PROXY,
--
1.7.3.4
More information about the samba-technical
mailing list