There's more that can be done (in particular, use of CLEANUP_FREE), but this is enough to at least see if I'm on the right track. I couldn't figure out an obvious difference between common/include and common/utils, but it looks like the former is for things that are inlineable via .h only, while the latter is when you need to link in a convenience library, so this landed in the latter. Eric Blake (4): cleanup: Move cleanup.c to common filters: Utilize CLEANUP_EXTENTS_FREE filters: Utilize ACQUIRE_LOCK_FOR_CURRENT_SCOPE plugins: Utilize ACQUIRE_LOCK_FOR_CURRENT_SCOPE common/utils/cleanup.h | 48 ++++++++++++++++++++++++++++++ server/internal.h | 12 +------- {server => common/utils}/cleanup.c | 5 ++-- filters/log/log.c | 10 +++---- filters/offset/offset.c | 13 ++++---- filters/partition/partition.c | 12 +++----- filters/readahead/readahead.c | 15 ++++------ filters/truncate/truncate.c | 12 +++----- plugins/data/data.c | 26 +++++----------- plugins/file/file.c | 18 ++++------- plugins/memory/memory.c | 26 +++++----------- plugins/nbd/nbd.c | 4 +-- common/utils/Makefile.am | 4 ++- filters/log/Makefile.am | 5 +++- filters/offset/Makefile.am | 5 +++- filters/partition/Makefile.am | 5 +++- filters/readahead/Makefile.am | 5 +++- filters/truncate/Makefile.am | 5 +++- plugins/data/Makefile.am | 4 ++- plugins/file/Makefile.am | 5 +++- plugins/memory/Makefile.am | 6 ++-- plugins/nbd/Makefile.am | 4 ++- server/Makefile.am | 7 +++-- 23 files changed, 137 insertions(+), 119 deletions(-) create mode 100644 common/utils/cleanup.h rename {server => common/utils}/cleanup.c (96%) -- 2.20.1