From 569f19fb9f89be96946d72a06ce545630d5b0cac6d87deea9c052d77699355b8 Mon Sep 17 00:00:00 2001 From: Dominique Leuenberger Date: Fri, 6 Sep 2013 17:44:27 +0000 Subject: [PATCH] Accepting request 196695 from home:mgorse:GNOME:Factory - Fix hang when registering with large numbers of service files (bnc#835984, avahi-reserve-space-for-record-data-when-size-e.patch). OBS-URL: https://build.opensuse.org/request/show/196695 OBS-URL: https://build.opensuse.org/package/show/GNOME:Factory/avahi?expand=0&rev=100 --- ...ve-space-for-record-data-when-size-e.patch | 119 ++++++++++++++++++ avahi.changes | 6 + avahi.spec | 3 + 3 files changed, 128 insertions(+) create mode 100644 avahi-reserve-space-for-record-data-when-size-e.patch diff --git a/avahi-reserve-space-for-record-data-when-size-e.patch b/avahi-reserve-space-for-record-data-when-size-e.patch new file mode 100644 index 0000000..53024d6 --- /dev/null +++ b/avahi-reserve-space-for-record-data-when-size-e.patch @@ -0,0 +1,119 @@ +From 5cf2d9e32dffc902ca5a6f0220904f8dca8ec055 Mon Sep 17 00:00:00 2001 +From: "Lee, Chun-Yi" +Date: Fri, 7 Sep 2012 04:37:33 +0800 +Subject: [PATCH] avahi-core: reserve space for record data when size estimate + +When we tested put a lot of airprint service files(have 45 to 60 flies), found there have cpu loadinghigh problem when start avahi-daemon with those service files. + +After traced source code, there have problem in probe-sched.c::elapse_callback causes doesn't have any probe job set to DONE so the daemon unlimited send out DNS package. +The root cause is when compare with the free package space in packet_add_probe_query before attach job key, the free package space doesn't include any record data that will attached after all keys attached. This defect causes whole DNS package is filled by job key, but doesn't remain enough space for any rdata. Then, that means have no job set to DONE. + +This patch add a new res_size member to AvahiDnsPacket, it used to sum the reserve size for record data the will attached after all keys attached. It can avoid keys consume whole size until p->size larger then p->max_size. + +Signed-off-by: Lee, Chun-Yi +--- + avahi-core/dns.c | 20 ++++++++++++++++++++ + avahi-core/dns.h | 4 +++- + avahi-core/probe-sched.c | 10 ++++++++-- + 3 files changed, 31 insertions(+), 3 deletions(-) + +diff --git a/avahi-core/dns.c b/avahi-core/dns.c +index 2fcd91f..523afdc 100644 +--- a/avahi-core/dns.c ++++ b/avahi-core/dns.c +@@ -55,6 +55,7 @@ AvahiDnsPacket* avahi_dns_packet_new(unsigned mtu) { + + p->size = p->rindex = AVAHI_DNS_PACKET_HEADER_SIZE; + p->max_size = max_size; ++ p->res_size = 0; + p->name_table = NULL; + p->data = NULL; + +@@ -833,6 +834,25 @@ size_t avahi_dns_packet_space(AvahiDnsPacket *p) { + return p->max_size - p->size; + } + ++size_t avahi_dns_packet_reserve_size(AvahiDnsPacket *p, size_t res_size) { ++ assert(p); ++ ++ assert(p->size + p->res_size <= p->max_size); ++ ++ if ((p->size + p->res_size + res_size) <= p->max_size) ++ p->res_size += res_size; ++ ++ return p->res_size; ++} ++ ++size_t avahi_dns_packet_reserved_space(AvahiDnsPacket *p) { ++ assert(p); ++ ++ assert(p->size + p->res_size <= p->max_size); ++ ++ return p->max_size - p->size - p->res_size; ++} ++ + int avahi_rdata_parse(AvahiRecord *record, const void* rdata, size_t size) { + int ret; + AvahiDnsPacket p; +diff --git a/avahi-core/dns.h b/avahi-core/dns.h +index 52e8d88..13b1ac2 100644 +--- a/avahi-core/dns.h ++++ b/avahi-core/dns.h +@@ -30,7 +30,7 @@ + #define AVAHI_DNS_PACKET_SIZE_MAX (AVAHI_DNS_PACKET_HEADER_SIZE + 256 + 2 + 2 + 4 + 2 + AVAHI_DNS_RDATA_MAX) + + typedef struct AvahiDnsPacket { +- size_t size, rindex, max_size; ++ size_t size, rindex, max_size, res_size; + AvahiHashmap *name_table; /* for name compression */ + uint8_t *data; + } AvahiDnsPacket; +@@ -78,6 +78,8 @@ int avahi_dns_packet_skip(AvahiDnsPacket *p, size_t length); + + int avahi_dns_packet_is_empty(AvahiDnsPacket *p); + size_t avahi_dns_packet_space(AvahiDnsPacket *p); ++size_t avahi_dns_packet_reserve_size(AvahiDnsPacket *p, size_t res_size); ++size_t avahi_dns_packet_reserved_space(AvahiDnsPacket *p); + + #define AVAHI_DNS_FIELD_ID 0 + #define AVAHI_DNS_FIELD_FLAGS 1 +diff --git a/avahi-core/probe-sched.c b/avahi-core/probe-sched.c +index 1e63411..63cb817 100644 +--- a/avahi-core/probe-sched.c ++++ b/avahi-core/probe-sched.c +@@ -179,7 +179,7 @@ static int packet_add_probe_query(AvahiProbeScheduler *s, AvahiDnsPacket *p, Ava + avahi_record_get_estimate_size(pj->record); + + /* Too large */ +- if (size > avahi_dns_packet_space(p)) ++ if (size > avahi_dns_packet_reserved_space(p)) + return 0; + + /* Create the probe query */ +@@ -189,6 +189,9 @@ static int packet_add_probe_query(AvahiProbeScheduler *s, AvahiDnsPacket *p, Ava + b = !!avahi_dns_packet_append_key(p, k, 0); + assert(b); + ++ /* reserve size for record data */ ++ avahi_dns_packet_reserve_size(p, avahi_record_get_estimate_size(pj->record)); ++ + /* Mark this job for addition to the packet */ + pj->chosen = 1; + +@@ -202,9 +205,12 @@ static int packet_add_probe_query(AvahiProbeScheduler *s, AvahiDnsPacket *p, Ava + continue; + + /* This job wouldn't fit in */ +- if (avahi_record_get_estimate_size(pj->record) > avahi_dns_packet_space(p)) ++ if (avahi_record_get_estimate_size(pj->record) > avahi_dns_packet_reserved_space(p)) + break; + ++ /* reserve size for record data */ ++ avahi_dns_packet_reserve_size(p, avahi_record_get_estimate_size(pj->record)); ++ + /* Mark this job for addition to the packet */ + pj->chosen = 1; + } +-- +1.7.10.4 + diff --git a/avahi.changes b/avahi.changes index f278015..0f17455 100644 --- a/avahi.changes +++ b/avahi.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Wed Aug 21 21:53:19 UTC 2013 - mgorse@suse.com + +- Fix hang when registering with large numbers of service files + (bnc#835984, avahi-reserve-space-for-record-data-when-size-e.patch). + ------------------------------------------------------------------- Mon Feb 4 16:59:54 CET 2013 - sbrabec@suse.cz diff --git a/avahi.spec b/avahi.spec index 5e4c33a..9eabbcf 100644 --- a/avahi.spec +++ b/avahi.spec @@ -92,6 +92,8 @@ Patch13: avahi-fix-mkdir.diff Patch14: avahi-enable-ipv6.patch # PATCH-FIX-OPENSUSE avahi-move-everything-to-run.patch rmilasan@suse.com -- Move everything to /run directory (socket and pid files) Patch15: avahi-move-everything-to-run.patch +# PATCH-FIX-OPENSUSE avahi-reserve-space-for-record-data-when-size-e.patch bnc#835984 jlee@suse.com -- avahi-core: reserve space for record data when size estimate +Patch16: avahi-reserve-space-for-record-data-when-size-e.patch BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: dbus-1-python BuildRequires: fdupes @@ -765,6 +767,7 @@ translation-update-upstream %patch13 -p1 %patch14 -p1 %patch15 -p1 +%patch16 -p1 %if !%build_core # Replace all .la references from local .la files to installed versions