From: Matthew Dillon Date: Mon, 11 Jan 2010 00:17:47 +0000 (-0800) Subject: HAMMER utility - Fix bug in hammer cleanup which causes the utility to exit X-Git-Tag: v2.7.1~229^2~125 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/ec2aa11dba2a5046a11e027db84799925e78e3dc HAMMER utility - Fix bug in hammer cleanup which causes the utility to exit * Remove debugging code which exit()ed when unable to delete a snapshot softlink. This caused 'hammer cleanup' to potentially not process all available HAMMER filesystems, amoung other things. * Rework the snapshot deletion code to skip any snapshots that cannot be deleted. --- diff --git a/sbin/hammer/cmd_cleanup.c b/sbin/hammer/cmd_cleanup.c index e5d9e2db42..4bee7ea134 100644 --- a/sbin/hammer/cmd_cleanup.c +++ b/sbin/hammer/cmd_cleanup.c @@ -81,6 +81,7 @@ static void save_period(const char *snapshots_path, const char *cmd, static int check_softlinks(int fd, int new_config, const char *snapshots_path); static void cleanup_softlinks(int fd, int new_config, const char *snapshots_path, int arg2, char *arg3); +static void delete_snapshots(int fd, struct hammer_ioc_snapshot *dsnapshot); static int check_expired(const char *fpath, int arg2); static int create_snapshot(const char *path, const char *snapshots_path); @@ -898,6 +899,7 @@ cleanup_softlinks(int fd, int new_config, struct hammer_snapshot_data *snap; struct tm *tp; time_t t; + time_t dt; char snapts[32]; u_int32_t i; @@ -911,12 +913,13 @@ cleanup_softlinks(int fd, int new_config, } for (i = 0; i < snapshot.count; ++i) { snap = &snapshot.snaps[i]; - t = time(NULL) - snap->ts / 1000000ULL; - if ((int)t > arg2 && snap->tid != 0) { + t = snap->ts / 1000000ULL; + dt = time(NULL) - t; + if ((int)dt > arg2 || snap->tid == 0) { dsnapshot.snaps[dsnapshot.count++] = *snap; } - if ((int)t > arg2 && VerboseOpt) { + if ((int)dt > arg2 && VerboseOpt) { tp = localtime(&t); strftime(snapts, sizeof(snapts), "%Y-%m-%d %H:%M:%S %Z", tp); @@ -925,31 +928,38 @@ cleanup_softlinks(int fd, int new_config, snapts, snap->label); } - if (dsnapshot.count == HAMMER_SNAPS_PER_IOCTL) { - if (ioctl(fd, HAMMERIOC_DEL_SNAPSHOT, &dsnapshot) < 0) { - printf(" Ioctl to delete snapshots failed: %s index %d\n", strerror(errno), dsnapshot.index); - } else if (dsnapshot.head.error) { - printf(" Ioctl to delete snapshots failed: %s\n", strerror(dsnapshot.head.error)); - exit(1); - } - dsnapshot.index = 0; - dsnapshot.count = 0; - dsnapshot.head.error = 0; - } + if (dsnapshot.count == HAMMER_SNAPS_PER_IOCTL) + delete_snapshots(fd, &dsnapshot); } } while (snapshot.head.error == 0 && snapshot.count); - if (dsnapshot.count) { - if (ioctl(fd, HAMMERIOC_DEL_SNAPSHOT, &dsnapshot) < 0) { - printf(" Ioctl to delete snapshots failed: %s\n", strerror(errno)); - } else if (dsnapshot.head.error) { - printf(" Ioctl to delete snapshots failed: %s\n", strerror(dsnapshot.head.error)); - } - dsnapshot.count = 0; - dsnapshot.index = 0; - dsnapshot.head.error = 0; + if (dsnapshot.count) + delete_snapshots(fd, &dsnapshot); + } +} + +static void +delete_snapshots(int fd, struct hammer_ioc_snapshot *dsnapshot) +{ + for (;;) { + if (ioctl(fd, HAMMERIOC_DEL_SNAPSHOT, dsnapshot) < 0) { + printf(" Ioctl to delete snapshots failed: %s\n", + strerror(errno)); + break; } + if (dsnapshot->head.error) { + printf(" Ioctl to delete snapshots failed at " + "snap=%016jx: %s\n", + dsnapshot->snaps[dsnapshot->index].tid, + strerror(dsnapshot->head.error)); + if (++dsnapshot->index < dsnapshot->count) + continue; + } + break; } + dsnapshot->index = 0; + dsnapshot->count = 0; + dsnapshot->head.error = 0; } /*