]> xenbits.xensource.com Git - libvirt.git/commit
qemu: support VIR_DOMAIN_DESTROY_REMOVE_LOGS flag
authorNikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Mon, 14 Feb 2022 12:19:52 +0000 (15:19 +0300)
committerNikolay Shirokovskiy <nikolay.shirokovskiy@openvz.org>
Wed, 6 Apr 2022 07:48:04 +0000 (10:48 +0300)
commita414cb76e37db4c1c79bde63f7ebd2d014253ae8
tree8a5bf2847a69b44b71c6a76d2cfb0b3bfad055aa
parentce3f707af51b95251992d5cdfd825f93b5564ea8
qemu: support VIR_DOMAIN_DESTROY_REMOVE_LOGS flag

Note that we attempt to remove logs only if virtlogd is in use.
Otherwise we do not know the pattern for rotated files.

For example for VM named "foo" we can not use "foo.log*" pattern to
remove rotated logs as we can have VM named "foo.log" with log
"foo.log.log".  We can add extra check that filename does not end with
".log" but for VM "foo.log" we can have rotated log "foo.log.log.1". Ok
let's check we don't have "log" in filename part corresponging to * but
what if someone will use logrotate with "%Y.log-%m-%d" 'dateformat'
option. In this case the check will exclude proper rotated files.

Yes, the last example if quite artificial but it shows it is difficult
to find out correctly rotated files when rotated files pattern is not
known. Thus the above decision only to support case with virtlogd when
we know the pattern.

Another reason for not removing log files when logrotate is present is
that due to races some files can escape deletion. For example foo.log.3
will be rotated to foo.log.4 after removing function will read directory
files and thus foo.log.4 will not be deleted.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_domain.c
src/qemu/qemu_domain.h
src/qemu/qemu_driver.c