|
|
932fb9 |
From 86e213fbd0d24b5b2e58d474d27d47b222011936 Mon Sep 17 00:00:00 2001
|
|
|
932fb9 |
From: "Lee, Chun-Yi" <jlee at suse.com>
|
|
|
932fb9 |
Date: Mon, 10 Sep 2012 10:27:56 +0800
|
|
|
932fb9 |
Subject: [PATCH 4/4] avahi-core: reserve space for record data when size
|
|
|
932fb9 |
estimate
|
|
|
932fb9 |
|
|
|
932fb9 |
When we tested put a lot of airprint service files(have 45 to 60 flies), found
|
|
|
932fb9 |
there have cpu loadinghigh problem when start avahi-daemon with those service
|
|
|
932fb9 |
files.
|
|
|
932fb9 |
|
|
|
932fb9 |
After traced source code, there have problem in probe-sched.c::elapse_callback
|
|
|
932fb9 |
causes doesn't have any probe job set to DONE so the daemon unlimited send out
|
|
|
932fb9 |
DNS package.
|
|
|
932fb9 |
|
|
|
932fb9 |
The root cause is when compare with the free package space in
|
|
|
932fb9 |
packet_add_probe_query before attach job key, the free package space doesn't
|
|
|
932fb9 |
include any record data that will attached after all keys attached. This defect
|
|
|
932fb9 |
causes whole DNS package is filled by job key, but doesn't remain enough space
|
|
|
932fb9 |
for any rdata. Then, that means have no job set to DONE.
|
|
|
932fb9 |
|
|
|
932fb9 |
This patch add a new res_size member to AvahiDnsPacket, it used to sum the
|
|
|
932fb9 |
reserve size for record data the will attached after all keys attached. It can
|
|
|
932fb9 |
avoid keys consume whole size until p->size larger then p->max_size.
|
|
|
932fb9 |
|
|
|
932fb9 |
Resolves: #1081801
|
|
|
932fb9 |
---
|
|
|
932fb9 |
avahi-core/dns.c | 20 ++++++++++++++++++++
|
|
|
932fb9 |
avahi-core/dns.h | 4 +++-
|
|
|
932fb9 |
avahi-core/probe-sched.c | 10 ++++++++--
|
|
|
932fb9 |
3 files changed, 31 insertions(+), 3 deletions(-)
|
|
|
932fb9 |
|
|
|
932fb9 |
diff --git a/avahi-core/dns.c b/avahi-core/dns.c
|
|
|
932fb9 |
index 2fcd91f..523afdc 100644
|
|
|
932fb9 |
--- a/avahi-core/dns.c
|
|
|
932fb9 |
+++ b/avahi-core/dns.c
|
|
|
932fb9 |
@@ -55,6 +55,7 @@ AvahiDnsPacket* avahi_dns_packet_new(unsigned mtu) {
|
|
|
932fb9 |
|
|
|
932fb9 |
p->size = p->rindex = AVAHI_DNS_PACKET_HEADER_SIZE;
|
|
|
932fb9 |
p->max_size = max_size;
|
|
|
932fb9 |
+ p->res_size = 0;
|
|
|
932fb9 |
p->name_table = NULL;
|
|
|
932fb9 |
p->data = NULL;
|
|
|
932fb9 |
|
|
|
932fb9 |
@@ -833,6 +834,25 @@ size_t avahi_dns_packet_space(AvahiDnsPacket *p) {
|
|
|
932fb9 |
return p->max_size - p->size;
|
|
|
932fb9 |
}
|
|
|
932fb9 |
|
|
|
932fb9 |
+size_t avahi_dns_packet_reserve_size(AvahiDnsPacket *p, size_t res_size) {
|
|
|
932fb9 |
+ assert(p);
|
|
|
932fb9 |
+
|
|
|
932fb9 |
+ assert(p->size + p->res_size <= p->max_size);
|
|
|
932fb9 |
+
|
|
|
932fb9 |
+ if ((p->size + p->res_size + res_size) <= p->max_size)
|
|
|
932fb9 |
+ p->res_size += res_size;
|
|
|
932fb9 |
+
|
|
|
932fb9 |
+ return p->res_size;
|
|
|
932fb9 |
+}
|
|
|
932fb9 |
+
|
|
|
932fb9 |
+size_t avahi_dns_packet_reserved_space(AvahiDnsPacket *p) {
|
|
|
932fb9 |
+ assert(p);
|
|
|
932fb9 |
+
|
|
|
932fb9 |
+ assert(p->size + p->res_size <= p->max_size);
|
|
|
932fb9 |
+
|
|
|
932fb9 |
+ return p->max_size - p->size - p->res_size;
|
|
|
932fb9 |
+}
|
|
|
932fb9 |
+
|
|
|
932fb9 |
int avahi_rdata_parse(AvahiRecord *record, const void* rdata, size_t size) {
|
|
|
932fb9 |
int ret;
|
|
|
932fb9 |
AvahiDnsPacket p;
|
|
|
932fb9 |
diff --git a/avahi-core/dns.h b/avahi-core/dns.h
|
|
|
932fb9 |
index 52e8d88..13b1ac2 100644
|
|
|
932fb9 |
--- a/avahi-core/dns.h
|
|
|
932fb9 |
+++ b/avahi-core/dns.h
|
|
|
932fb9 |
@@ -30,7 +30,7 @@
|
|
|
932fb9 |
#define AVAHI_DNS_PACKET_SIZE_MAX (AVAHI_DNS_PACKET_HEADER_SIZE + 256 + 2 + 2 + 4 + 2 + AVAHI_DNS_RDATA_MAX)
|
|
|
932fb9 |
|
|
|
932fb9 |
typedef struct AvahiDnsPacket {
|
|
|
932fb9 |
- size_t size, rindex, max_size;
|
|
|
932fb9 |
+ size_t size, rindex, max_size, res_size;
|
|
|
932fb9 |
AvahiHashmap *name_table; /* for name compression */
|
|
|
932fb9 |
uint8_t *data;
|
|
|
932fb9 |
} AvahiDnsPacket;
|
|
|
932fb9 |
@@ -78,6 +78,8 @@ int avahi_dns_packet_skip(AvahiDnsPacket *p, size_t length);
|
|
|
932fb9 |
|
|
|
932fb9 |
int avahi_dns_packet_is_empty(AvahiDnsPacket *p);
|
|
|
932fb9 |
size_t avahi_dns_packet_space(AvahiDnsPacket *p);
|
|
|
932fb9 |
+size_t avahi_dns_packet_reserve_size(AvahiDnsPacket *p, size_t res_size);
|
|
|
932fb9 |
+size_t avahi_dns_packet_reserved_space(AvahiDnsPacket *p);
|
|
|
932fb9 |
|
|
|
932fb9 |
#define AVAHI_DNS_FIELD_ID 0
|
|
|
932fb9 |
#define AVAHI_DNS_FIELD_FLAGS 1
|
|
|
932fb9 |
diff --git a/avahi-core/probe-sched.c b/avahi-core/probe-sched.c
|
|
|
932fb9 |
index 1e63411..63cb817 100644
|
|
|
932fb9 |
--- a/avahi-core/probe-sched.c
|
|
|
932fb9 |
+++ b/avahi-core/probe-sched.c
|
|
|
932fb9 |
@@ -179,7 +179,7 @@ static int packet_add_probe_query(AvahiProbeScheduler *s, AvahiDnsPacket *p, Ava
|
|
|
932fb9 |
avahi_record_get_estimate_size(pj->record);
|
|
|
932fb9 |
|
|
|
932fb9 |
/* Too large */
|
|
|
932fb9 |
- if (size > avahi_dns_packet_space(p))
|
|
|
932fb9 |
+ if (size > avahi_dns_packet_reserved_space(p))
|
|
|
932fb9 |
return 0;
|
|
|
932fb9 |
|
|
|
932fb9 |
/* Create the probe query */
|
|
|
932fb9 |
@@ -189,6 +189,9 @@ static int packet_add_probe_query(AvahiProbeScheduler *s, AvahiDnsPacket *p, Ava
|
|
|
932fb9 |
b = !!avahi_dns_packet_append_key(p, k, 0);
|
|
|
932fb9 |
assert(b);
|
|
|
932fb9 |
|
|
|
932fb9 |
+ /* reserve size for record data */
|
|
|
932fb9 |
+ avahi_dns_packet_reserve_size(p, avahi_record_get_estimate_size(pj->record));
|
|
|
932fb9 |
+
|
|
|
932fb9 |
/* Mark this job for addition to the packet */
|
|
|
932fb9 |
pj->chosen = 1;
|
|
|
932fb9 |
|
|
|
932fb9 |
@@ -202,9 +205,12 @@ static int packet_add_probe_query(AvahiProbeScheduler *s, AvahiDnsPacket *p, Ava
|
|
|
932fb9 |
continue;
|
|
|
932fb9 |
|
|
|
932fb9 |
/* This job wouldn't fit in */
|
|
|
932fb9 |
- if (avahi_record_get_estimate_size(pj->record) > avahi_dns_packet_space(p))
|
|
|
932fb9 |
+ if (avahi_record_get_estimate_size(pj->record) > avahi_dns_packet_reserved_space(p))
|
|
|
932fb9 |
break;
|
|
|
932fb9 |
|
|
|
932fb9 |
+ /* reserve size for record data */
|
|
|
932fb9 |
+ avahi_dns_packet_reserve_size(p, avahi_record_get_estimate_size(pj->record));
|
|
|
932fb9 |
+
|
|
|
932fb9 |
/* Mark this job for addition to the packet */
|
|
|
932fb9 |
pj->chosen = 1;
|
|
|
932fb9 |
}
|
|
|
932fb9 |
--
|
|
|
932fb9 |
2.3.4
|
|
|
932fb9 |
|