[PATCH] Refactor common code from nscd's two main poll loops.
Andreas Jaeger
aj@suse.com
Fri Feb 8 10:50:00 GMT 2013
On 02/07/2013 11:02 PM, Carlos O'Donell wrote:
> Team,
>
> While working on some nscd issues I caused myself some grief
> by not noticing that we have quite a bit of duplicate code
> in both the main_loop_poll and main_loop_epoll functions.
>
> This patch does two things:
> (1) Adds more comments.
> (2) Refactors two chunks of identical code out of the
> two main poll loops.
>
> The resulting code is easier to review and maintain.
>
> No regressions on x86-64, tested the resulting nscd locally
> with no issues. Verified that the produced object files
> show both functions inlined into main_loop_*poll and
> equivalent object code produced.
>
> OK to checkin?
>
> 2013-02-07 Carlos O'Donell <carlos@redhat.com>
>
> * nscd/connection.c (register_traced_file): Comment function.
> [HAVE_INOTIFY] (union __inev): Define.
> [HAVE_INOTIFY] (inotify_check_files): New function.
> [HAVE_INOTIFY] (clear_db_cache): Likewise.
> [HAVE_INOTIFY] (main_loop_poll): Call inotify_check_files and
> clear_db_cache.
> [HAVE_INOTIFY] (main_loop_epoll): Likewise.
>
> diff --git a/nscd/connections.c b/nscd/connections.c
> index f6e2328..44a8bfb 100644
> --- a/nscd/connections.c
> +++ b/nscd/connections.c
> @@ -976,9 +976,25 @@ cannot change socket to nonblocking mode: %s"),
> }
>
>
> +/* Register the file in FINFO as a traced file for the database DBS[DBIX].
> +
> + We support registering multiple files per database. Each call to
> + register_traced_file adds to the list of registered files.
> +
> + When we prune the database, either through timeout or a request to
> + invalidate, we will check to see if any of the registered files has changed.
> + When we accept new connections to handle a cache request we will also
> + check to see if any of the registered files has changed.
> +
> + If we have inotify support then we install an inotify fd to notify us of
> + file deletion or modification, both of which will require we invalidate
> + the cache for the database. Without inotify support we stat the file and
> + store st_mtime to determine if the file has been modified. */
> void
> register_traced_file (size_t dbidx, struct traced_file *finfo)
> {
> + /* If the database is disabled or file checking is disabled
> + then ignore the registration. */
> if (! dbs[dbidx].enabled || ! dbs[dbidx].check_file)
> return;
>
> @@ -1870,6 +1886,63 @@ restart_p (time_t now)
> /* Array for times a connection was accepted. */
> static time_t *starttime;
>
> +#ifdef HAVE_INOTIFY
> +/* Inotify event for changed file. */
> +union __inev
> +{
> + struct inotify_event i;
> +# ifndef PATH_MAX
> +# define PATH_MAX 1024
> +# endif
> + char buf[sizeof (struct inotify_event) + PATH_MAX];
> +};
> +
> +/* Process the inotify event in INEV. If the event matches any of the files
> + registered with a database then mark that database as requiring its cache
> + to be cleared. We indicate the cache needs clearing by setting
> + TO_CLEAR[DBCNT] to true for the matching database. */
> +static inline void
> +inotify_check_files(bool *to_clear, union __inev *inev)
A space before the opening parenthesis.
Ok with this change,
Andreas
--
Andreas Jaeger aj@{suse.com,opensuse.org} Twitter/Identica: jaegerandi
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn,Jennifer Guild,Felix Imendörffer,HRB16746 (AG Nürnberg)
GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126
More information about the Libc-alpha
mailing list