journal-vacuum.c revision 2b43f939a4b3ad5aeb2650868b0234ff42ec0045
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen This file is part of systemd.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen Copyright 2011 Lennart Poettering
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen systemd is free software; you can redistribute it and/or modify it
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen under the terms of the GNU Lesser General Public License as published by
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen (at your option) any later version.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen systemd is distributed in the hope that it will be useful, but
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen Lesser General Public License for more details.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen You should have received a copy of the GNU Lesser General Public License
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenstatic int vacuum_compare(const void *_a, const void *_b) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen const struct vacuum_info *a, *b;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen return memcmp(&a->seqnum_id, &b->seqnum_id, 16);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersenint journal_directory_vacuum(const char *directory, uint64_t max_use, uint64_t min_free) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (k != 0) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (fstatat(dirfd(d), de->d_name, &st, AT_SYMLINK_NOFOLLOW) < 0)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /* Vacuum archived files */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (sd_id128_from_string(de->d_name + q-8-16-1-16-1-32, &seqnum_id) < 0) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (sscanf(de->d_name + q-8-16-1-16, "%16llx-%16llx.journal", &seqnum, &realtime) != 2) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen } else if (endswith(de->d_name, ".journal~")) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen unsigned long long tmp;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen /* Vacuum corrupted files */
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (sscanf(de->d_name + q-1-8-16-1-16, "%16llx-%16llx.journal~", &realtime, &tmp) != 2) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen j = realloc(list, n_allocated * sizeof(struct vacuum_info));
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen list[n_list].usage = 512UL * (uint64_t) st.st_blocks;
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen qsort(list, n_list, sizeof(struct vacuum_info), vacuum_compare);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen for(i = 0; i < n_list; i++) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen (uint64_t) ss.f_bavail * (uint64_t) ss.f_bsize >= min_free)
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen if (unlinkat(dirfd(d), list[i].filename, 0) >= 0) {
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_debug("Deleted archived journal %s/%s.", directory, list[i].filename);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen log_warning("Failed to delete %s/%s: %m", directory, list[i].filename);
57fa1d094cd2c5ac68970526ad0a0754c548e75dTom Gundersen for (i = 0; i < n_list; i++)