2 * Copyright (c) 2008 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $DragonFly: src/sbin/hammer/cmd_cleanup.c,v 1.6 2008/10/07 22:28:41 thomas Exp $
37 * Clean up specific HAMMER filesystems or all HAMMER filesystems.
39 * If no filesystems are specified any HAMMER- or null-mounted hammer PFS's
42 * Each HAMMER filesystem may contain a configuration file. If no
43 * configuration file is present one will be created with the following
46 * snapshots 1d 60d (0d 0d for /tmp, /var/tmp, /usr/obj)
52 * All hammer commands create and maintain cycle files in the snapshots
55 * For HAMMER version 2- the configuration file is a named 'config' in
56 * the snapshots directory, which defaults to <pfs>/snapshots.
57 * For HAMMER version 3+ the configuration file is saved in filesystem
58 * meta-data. The snapshots directory defaults to /var/hammer/<pfs>
59 * (/var/hammer/root for root mount).
69 static void do_cleanup(const char *path);
70 static void config_init(const char *path, struct hammer_ioc_config *config);
71 static void migrate_config(FILE *fp, struct hammer_ioc_config *config);
72 static void migrate_snapshots(int fd, const char *snapshots_path);
73 static void migrate_one_snapshot(int fd, const char *fpath,
74 struct hammer_ioc_snapshot *snapshot);
75 static int strtosecs(char *ptr);
76 static const char *dividing_slash(const char *path);
77 static int check_period(const char *snapshots_path, const char *cmd, int arg1,
79 static void save_period(const char *snapshots_path, const char *cmd,
81 static int check_softlinks(int fd, int new_config, const char *snapshots_path);
82 static void cleanup_softlinks(int fd, int new_config,
83 const char *snapshots_path, int arg2, char *arg3);
84 static int check_expired(const char *fpath, int arg2);
86 static int create_snapshot(const char *path, const char *snapshots_path);
87 static int cleanup_rebalance(const char *path, const char *snapshots_path,
89 static int cleanup_prune(const char *path, const char *snapshots_path,
90 int arg1, int arg2, int snapshots_disabled);
91 static int cleanup_reblock(const char *path, const char *snapshots_path,
93 static int cleanup_recopy(const char *path, const char *snapshots_path,
96 static void runcmd(int *resp, const char *ctl, ...);
99 * WARNING: Do not make the SNAPSHOTS_BASE "/var/snapshots" because
100 * it will interfere with the older HAMMER VERS < 3 snapshots directory
103 #define SNAPSHOTS_BASE "/var/hammer" /* HAMMER VERS >= 3 */
106 struct didpfs *FirstPFS;
109 hammer_cmd_cleanup(char **av, int ac)
111 char *fstype, *fs, *path;
112 struct statfs *stfsbuf;
117 mntsize = getmntinfo(&stfsbuf, MNT_NOWAIT);
119 for (i=0; i < mntsize; i++) {
121 * We will cleanup in the case fstype is hammer.
122 * If we have null-mounted PFS, we check the
123 * mount source. If it looks like a PFS, we
124 * proceed to cleanup also.
126 fstype = stfsbuf[i].f_fstypename;
127 fs = stfsbuf[i].f_mntfromname;
128 if ((strcmp(fstype, "hammer") == 0) ||
129 ((strcmp(fstype, "null") == 0) &&
130 (strstr(fs, "/@@0x") != NULL ||
131 strstr(fs, "/@@-1") != NULL))) {
132 path = stfsbuf[i].f_mntonname;
149 do_cleanup(const char *path)
151 struct hammer_ioc_pseudofs_rw pfs;
152 struct hammer_ioc_config config;
153 struct hammer_ioc_version version;
154 union hammer_ioc_mrecord_any mrec_tmp;
155 char *snapshots_path;
168 struct didpfs *didpfs;
169 int snapshots_disabled = 0;
170 int prune_warning = 0;
172 int snapshots_from_pfs = 0;
177 bzero(&pfs, sizeof(pfs));
178 bzero(&mrec_tmp, sizeof(mrec_tmp));
179 pfs.ondisk = &mrec_tmp.pfs.pfsd;
180 pfs.bytes = sizeof(mrec_tmp.pfs.pfsd);
183 printf("cleanup %-20s -", path);
184 fd = open(path, O_RDONLY);
186 printf(" unable to access directory: %s\n", strerror(errno));
189 if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) < 0) {
190 printf(" not a HAMMER filesystem: %s\n", strerror(errno));
194 if (pfs.version != HAMMER_IOC_PSEUDOFS_VERSION) {
195 printf(" unrecognized HAMMER version\n");
199 bzero(&version, sizeof(version));
200 if (ioctl(fd, HAMMERIOC_GET_VERSION, &version) < 0) {
201 printf(" HAMMER filesystem but couldn't retrieve version!\n");
206 bzero(&config, sizeof(config));
207 if (version.cur_version >= 3) {
208 if (ioctl(fd, HAMMERIOC_GET_CONFIG, &config) == 0 &&
209 config.head.error == 0) {
215 * Make sure we have not already handled this PFS. Several nullfs
216 * mounts might alias the same PFS.
218 for (didpfs = FirstPFS; didpfs; didpfs = didpfs->next) {
219 if (bcmp(&didpfs->uuid, &mrec_tmp.pfs.pfsd.unique_uuid, sizeof(uuid_t)) == 0) {
220 printf(" PFS #%d already handled\n", pfs.pfs_id);
225 didpfs = malloc(sizeof(*didpfs));
226 didpfs->next = FirstPFS;
228 didpfs->uuid = mrec_tmp.pfs.pfsd.unique_uuid;
231 * Calculate the old snapshots directory for HAMMER VERSION < 3
233 * If the directory is explicitly specified in the PFS config
234 * we flag it and will not migrate it later.
236 if (mrec_tmp.pfs.pfsd.snapshots[0] == '/') {
237 asprintf(&snapshots_path, "%s", mrec_tmp.pfs.pfsd.snapshots);
238 snapshots_from_pfs = 1;
239 } else if (mrec_tmp.pfs.pfsd.snapshots[0]) {
240 printf(" WARNING: pfs-slave's snapshots dir is not absolute\n");
243 } else if (mrec_tmp.pfs.pfsd.mirror_flags & HAMMER_PFSD_SLAVE) {
244 printf(" WARNING: must configure snapshot dir for PFS slave\n");
245 printf("\tWe suggest <fs>/var/slaves/<name> where "
246 "<fs> is the base HAMMER fs\n");
247 printf("\tcontaining the slave\n");
251 asprintf(&snapshots_path,
252 "%s%ssnapshots", path, dividing_slash(path));
256 * Check for old-style config file
258 asprintf(&config_path, "%s/config", snapshots_path);
259 fp = fopen(config_path, "r");
262 * Handle upgrades to hammer version 3, move the config
263 * file into meta-data.
265 * For the old config read the file into the config structure,
266 * we will parse it out of the config structure regardless.
268 if (version.cur_version >= 3) {
270 printf("(migrating) ");
272 migrate_config(fp, &config);
273 migrate_snapshots(fd, snapshots_path);
275 if (ioctl(fd, HAMMERIOC_SET_CONFIG, &config) < 0) {
276 printf(" cannot init meta-data config!\n");
281 } else if (new_config == 0) {
282 config_init(path, &config);
283 if (ioctl(fd, HAMMERIOC_SET_CONFIG, &config) < 0) {
284 printf(" cannot init meta-data config!\n");
292 * Create missing snapshots directory for HAMMER VERSION < 3
294 if (stat(snapshots_path, &st) < 0) {
295 if (mkdir(snapshots_path, 0755) != 0) {
296 free(snapshots_path);
297 printf(" unable to create snapshot dir \"%s\": %s\n",
298 snapshots_path, strerror(errno));
305 * Create missing config file for HAMMER VERSION < 3
308 config_init(path, &config);
309 fp = fopen(config_path, "w");
311 fwrite(config.config.text, 1,
312 strlen(config.config.text), fp);
316 migrate_config(fp, &config);
322 * If snapshots_from_pfs is not set we calculate the new snapshots
323 * directory default (in /var) for HAMMER VERSION >= 3 and migrate
324 * the old snapshots directory over.
326 * People who have set an explicit snapshots directory will have
327 * to migrate the data manually into /var/hammer, or not bother at
328 * all. People running slaves may wish to migrate it and then
329 * clear the snapshots specification in the PFS config for the
332 if (new_config && snapshots_from_pfs == 0) {
335 assert(path[0] == '/');
336 if (strcmp(path, "/") == 0)
337 asprintf(&npath, "%s/root", SNAPSHOTS_BASE);
339 asprintf(&npath, "%s/%s", SNAPSHOTS_BASE, path + 1);
340 if (stat(npath, &st) < 0 && errno == ENOENT) {
341 if (stat(snapshots_path, &st) < 0 && errno == ENOENT) {
342 printf(" HAMMER UPGRADE: Creating snapshots\n"
343 "\tCreating snapshots in %s\n",
345 runcmd(&r, "mkdir -p %s", npath);
347 printf(" HAMMER UPGRADE: Moving snapshots\n"
348 "\tMoving snapshots from %s to %s\n",
349 snapshots_path, npath);
350 runcmd(&r, "mkdir -p %s", npath);
351 runcmd(&r, "cpdup %s %s", snapshots_path, npath);
353 printf("Unable to move snapshots directory!\n");
354 printf("Please fix this critical error.\n");
355 printf("Aborting cleanup of %s\n", path);
359 runcmd(&r, "rm -rf %s", snapshots_path);
362 free(snapshots_path);
363 snapshots_path = npath;
367 * Lock the PFS. fd is the base directory of the mounted PFS.
369 if (flock(fd, LOCK_EX|LOCK_NB) == -1) {
370 if (errno == EWOULDBLOCK)
371 printf(" PFS #%d locked by other process\n", pfs.pfs_id);
373 printf(" can not lock %s: %s\n", config_path, strerror(errno));
378 printf(" handle PFS #%d using %s\n", pfs.pfs_id, snapshots_path);
381 * Process the config file
383 cbase = config.config.text;
385 while ((cptr = strchr(cbase, '\n')) != NULL) {
386 bcopy(cbase, buf, cptr - cbase);
387 buf[cptr - cbase] = 0;
390 cmd = strtok(buf, WS);
394 if ((ptr = strtok(NULL, WS)) != NULL) {
395 arg1 = strtosecs(ptr);
396 if ((ptr = strtok(NULL, WS)) != NULL) {
397 arg2 = strtosecs(ptr);
398 arg3 = strtok(NULL, WS);
402 printf("%20s - ", cmd);
406 if (strcmp(cmd, "snapshots") == 0) {
409 check_softlinks(fd, new_config,
411 printf("only removing old snapshots\n");
413 cleanup_softlinks(fd, new_config,
417 printf("disabled\n");
418 snapshots_disabled = 1;
421 if (check_period(snapshots_path, cmd, arg1, &savet)) {
423 cleanup_softlinks(fd, new_config,
426 r = create_snapshot(path, snapshots_path);
430 } else if (arg1 == 0) {
432 * The commands following this check can't handle
433 * a period of 0, so call the feature disabled and
434 * ignore the directive.
436 printf("disabled\n");
437 } else if (strcmp(cmd, "prune") == 0) {
438 if (check_period(snapshots_path, cmd, arg1, &savet)) {
440 printf("run - WARNING snapshot "
442 "but snapshots disabled\n");
446 r = cleanup_prune(path, snapshots_path,
447 arg1, arg2, snapshots_disabled);
451 } else if (strcmp(cmd, "rebalance") == 0) {
453 if (check_period(snapshots_path, cmd, arg1, &savet)) {
458 r = cleanup_rebalance(path, snapshots_path,
463 } else if (strcmp(cmd, "reblock") == 0) {
464 if (check_period(snapshots_path, cmd, arg1, &savet)) {
469 r = cleanup_reblock(path, snapshots_path,
474 } else if (strcmp(cmd, "recopy") == 0) {
475 if (check_period(snapshots_path, cmd, arg1, &savet)) {
480 r = cleanup_recopy(path, snapshots_path,
486 printf("unknown directive\n");
490 save_period(snapshots_path, cmd, savet);
494 * Add new rebalance feature if the config doesn't have it.
495 * (old style config only).
497 if (new_config == 0 && found_rebal == 0) {
498 if ((fp = fopen(config_path, "r+")) != NULL) {
500 fprintf(fp, "rebalance 1d 5m\n");
506 * Cleanup, and delay a little
513 * Initialize new config data (new or old style)
516 config_init(const char *path, struct hammer_ioc_config *config)
518 const char *snapshots;
520 if (strcmp(path, "/tmp") == 0 ||
521 strcmp(path, "/var/tmp") == 0 ||
522 strcmp(path, "/usr/obj") == 0) {
523 snapshots = "snapshots 0d 0d\n";
525 snapshots = "snapshots 1d 60d\n";
527 bzero(config->config.text, sizeof(config->config.text));
528 snprintf(config->config.text, sizeof(config->config.text) - 1, "%s%s",
537 * Migrate configuration data from the old snapshots/config
538 * file to the new meta-data format.
541 migrate_config(FILE *fp, struct hammer_ioc_config *config)
545 n = fread(config->config.text, 1, sizeof(config->config.text) - 1, fp);
547 bzero(config->config.text + n, sizeof(config->config.text) - n);
551 * Migrate snapshot softlinks in the snapshots directory to the
552 * new meta-data format. The softlinks are left intact, but
553 * this way the pruning code won't lose track of them if you
554 * happen to blow away the snapshots directory.
557 migrate_snapshots(int fd, const char *snapshots_path)
559 struct hammer_ioc_snapshot snapshot;
565 bzero(&snapshot, sizeof(snapshot));
567 if ((dir = opendir(snapshots_path)) != NULL) {
568 while ((den = readdir(dir)) != NULL) {
569 if (den->d_name[0] == '.')
571 asprintf(&fpath, "%s/%s", snapshots_path, den->d_name);
572 if (lstat(fpath, &st) == 0 && S_ISLNK(st.st_mode)) {
573 migrate_one_snapshot(fd, fpath, &snapshot);
579 migrate_one_snapshot(fd, NULL, &snapshot);
584 * Migrate a single snapshot. If fpath is NULL the ioctl is flushed,
585 * otherwise it is flushed when it fills up.
588 migrate_one_snapshot(int fd, const char *fpath,
589 struct hammer_ioc_snapshot *snapshot)
592 struct hammer_snapshot_data *snap;
606 tid = (hammer_tid_t)(int64_t)-1;
609 while (*ptr && *ptr != '-' && *ptr != '.')
613 r = sscanf(ptr, "%4d%2d%2d-%2d%2d",
614 &year, &month, &day, &hour, &minute);
617 bzero(&tm, sizeof(tm));
622 tm.tm_mon = month - 1;
623 tm.tm_year = year - 1900;
626 bzero(linkbuf, sizeof(linkbuf));
627 if (readlink(fpath, linkbuf, sizeof(linkbuf) - 1) > 0 &&
628 (ptr = strrchr(linkbuf, '@')) != NULL &&
629 ptr > linkbuf && ptr[-1] == '@') {
630 tid = strtoull(ptr + 1, NULL, 16);
632 if (t != (time_t)-1 && tid != (hammer_tid_t)(int64_t)-1) {
633 snap = &snapshot->snaps[snapshot->count];
634 bzero(snap, sizeof(*snap));
636 snap->ts = (u_int64_t)t * 1000000ULL;
637 snprintf(snap->label, sizeof(snap->label),
643 if ((fpath == NULL && snapshot->count) ||
644 snapshot->count == HAMMER_SNAPS_PER_IOCTL) {
645 printf(" (%d snapshots)", snapshot->count);
647 if (ioctl(fd, HAMMERIOC_ADD_SNAPSHOT, snapshot) < 0) {
648 printf(" Ioctl to migrate snapshots failed: %s\n",
650 } else if (snapshot->head.error == EALREADY) {
653 } else if (snapshot->head.error) {
654 printf(" Ioctl to migrate snapshots failed: %s\n",
655 strerror(snapshot->head.error));
657 printf("index %d\n", snapshot->index);
660 snapshot->head.error = 0;
670 val = strtol(ptr, &ptr, 0);
684 errx(1, "illegal suffix converting %s\n", ptr);
691 dividing_slash(const char *path)
693 int len = strlen(path);
694 if (len && path[len-1] == '/')
701 * Check whether the desired period has elapsed since the last successful
702 * run. The run may take a while and cross a boundary so we remember the
703 * current time_t so we can save it later on.
705 * Periods in minutes, hours, or days are assumed to have been crossed
706 * if the local time crosses a minute, hour, or day boundary regardless
707 * of how close the last operation actually was.
710 check_period(const char *snapshots_path, const char *cmd, int arg1,
721 localtime_r(savep, &tp1);
724 * Retrieve the start time of the last successful operation.
726 asprintf(&check_path, "%s/.%s.period", snapshots_path, cmd);
727 fp = fopen(check_path, "r");
731 if (fgets(buf, sizeof(buf), fp) == NULL) {
737 lastt = strtol(buf, NULL, 0);
738 localtime_r(&lastt, &tp2);
741 * Normalize the times. e.g. if asked to do something on a 1-day
742 * interval the operation will be performed as soon as the day
743 * turns over relative to the previous operation, even if the previous
744 * operation ran a few seconds ago just before midnight.
746 if (arg1 % 60 == 0) {
750 if (arg1 % (60 * 60) == 0) {
754 if (arg1 % (24 * 60 * 60) == 0) {
759 baset = mktime(&tp1);
760 lastt = mktime(&tp2);
763 printf("%lld vs %lld\n", (long long)(baset - lastt), (long long)arg1);
766 if ((int)(baset - lastt) >= arg1)
772 * Store the start time of the last successful operation.
775 save_period(const char *snapshots_path, const char *cmd,
782 asprintf(&ocheck_path, "%s/.%s.period", snapshots_path, cmd);
783 asprintf(&ncheck_path, "%s/.%s.period.new", snapshots_path, cmd);
784 fp = fopen(ncheck_path, "w");
786 fprintf(fp, "0x%08llx\n", (long long)savet);
788 rename(ncheck_path, ocheck_path);
791 fprintf(stderr, "hammer: Unable to create period-file %s: %s\n",
792 ncheck_path, strerror(errno));
797 * Simply count the number of softlinks in the snapshots dir
800 check_softlinks(int fd, int new_config, const char *snapshots_path)
809 * Old-style softlink-based snapshots
811 if ((dir = opendir(snapshots_path)) != NULL) {
812 while ((den = readdir(dir)) != NULL) {
813 if (den->d_name[0] == '.')
815 asprintf(&fpath, "%s/%s", snapshots_path, den->d_name);
816 if (lstat(fpath, &st) == 0 && S_ISLNK(st.st_mode))
824 * New-style snapshots are stored as filesystem meta-data,
828 struct hammer_ioc_snapshot snapshot;
830 bzero(&snapshot, sizeof(snapshot));
832 if (ioctl(fd, HAMMERIOC_GET_SNAPSHOT, &snapshot) < 0) {
833 err(2, "hammer cleanup: check_softlink "
837 res += snapshot.count;
838 } while (snapshot.head.error == 0 && snapshot.count);
844 * Clean up expired softlinks in the snapshots dir
847 cleanup_softlinks(int fd, int new_config,
848 const char *snapshots_path, int arg2, char *arg3)
856 if (arg3 != NULL && strstr(arg3, "any") != NULL)
859 if ((dir = opendir(snapshots_path)) != NULL) {
860 while ((den = readdir(dir)) != NULL) {
861 if (den->d_name[0] == '.')
863 asprintf(&fpath, "%s/%s", snapshots_path, den->d_name);
864 if (lstat(fpath, &st) == 0 && S_ISLNK(st.st_mode) &&
865 (anylink || strncmp(den->d_name, "snap-", 5) == 0)
867 if (check_expired(den->d_name, arg2)) {
869 printf(" expire %s\n",
881 * New-style snapshots are stored as filesystem meta-data,
885 struct hammer_ioc_snapshot snapshot;
886 struct hammer_ioc_snapshot dsnapshot;
887 struct hammer_snapshot_data *snap;
893 bzero(&snapshot, sizeof(snapshot));
894 bzero(&dsnapshot, sizeof(dsnapshot));
896 if (ioctl(fd, HAMMERIOC_GET_SNAPSHOT, &snapshot) < 0) {
897 err(2, "hammer cleanup: check_softlink "
901 for (i = 0; i < snapshot.count; ++i) {
902 snap = &snapshot.snaps[i];
903 t = time(NULL) - snap->ts / 1000000ULL;
904 if ((int)t > arg2 && snap->tid != 0) {
905 dsnapshot.snaps[dsnapshot.count++] =
908 if ((int)t > arg2 && VerboseOpt) {
910 strftime(snapts, sizeof(snapts),
911 "%Y-%m-%d %H:%M:%S %Z", tp);
912 printf(" expire 0x%016jx %s %s\n",
913 (uintmax_t)snap->tid,
917 if (dsnapshot.count == HAMMER_SNAPS_PER_IOCTL) {
918 if (ioctl(fd, HAMMERIOC_DEL_SNAPSHOT, &dsnapshot) < 0) {
919 printf(" Ioctl to delete snapshots failed: %s index %d\n", strerror(errno), dsnapshot.index);
920 } else if (dsnapshot.head.error) {
921 printf(" Ioctl to delete snapshots failed: %s\n", strerror(dsnapshot.head.error));
926 dsnapshot.head.error = 0;
929 } while (snapshot.head.error == 0 && snapshot.count);
931 if (dsnapshot.count) {
932 if (ioctl(fd, HAMMERIOC_DEL_SNAPSHOT, &dsnapshot) < 0) {
933 printf(" Ioctl to delete snapshots failed: %s\n", strerror(errno));
934 } else if (dsnapshot.head.error) {
935 printf(" Ioctl to delete snapshots failed: %s\n", strerror(dsnapshot.head.error));
939 dsnapshot.head.error = 0;
945 * Take a softlink path in the form snap-yyyymmdd-hhmm and the
946 * expiration in seconds (arg2) and return non-zero if the softlink
950 check_expired(const char *fpath, int arg2)
961 while (*fpath && *fpath != '-' && *fpath != '.')
966 r = sscanf(fpath, "%4d%2d%2d-%2d%2d",
967 &year, &month, &day, &hour, &minute);
970 bzero(&tm, sizeof(tm));
975 tm.tm_mon = month - 1;
976 tm.tm_year = year - 1900;
991 create_snapshot(const char *path, const char *snapshots_path)
995 runcmd(&r, "hammer snapshot %s %s", path, snapshots_path);
1000 cleanup_prune(const char *path __unused, const char *snapshots_path,
1001 int arg1 __unused, int arg2, int snapshots_disabled)
1004 * If snapshots have been disabled run prune-everything instead
1007 if (snapshots_disabled && arg2) {
1008 runcmd(NULL, "hammer -c %s/.prune.cycle -t %d prune-everything %s",
1009 snapshots_path, arg2, path);
1010 } else if (snapshots_disabled) {
1011 runcmd(NULL, "hammer prune-everything %s", path);
1013 runcmd(NULL, "hammer -c %s/.prune.cycle -t %d prune %s",
1014 snapshots_path, arg2, snapshots_path);
1016 runcmd(NULL, "hammer prune %s", snapshots_path);
1022 cleanup_rebalance(const char *path, const char *snapshots_path,
1023 int arg1 __unused, int arg2)
1025 if (VerboseOpt == 0) {
1031 "hammer -c %s/.rebalance.cycle -t %d rebalance %s",
1032 snapshots_path, arg2, path);
1033 if (VerboseOpt == 0) {
1037 if (VerboseOpt == 0)
1043 cleanup_reblock(const char *path, const char *snapshots_path,
1044 int arg1 __unused, int arg2)
1046 if (VerboseOpt == 0) {
1052 * When reblocking the B-Tree always reblock everything in normal
1056 "hammer -c %s/.reblock-1.cycle -t %d reblock-btree %s",
1057 snapshots_path, arg2, path);
1058 if (VerboseOpt == 0) {
1064 * When reblocking the inodes always reblock everything in normal
1068 "hammer -c %s/.reblock-2.cycle -t %d reblock-inodes %s",
1069 snapshots_path, arg2, path);
1070 if (VerboseOpt == 0) {
1076 * When reblocking the directories always reblock everything in normal
1080 "hammer -c %s/.reblock-4.cycle -t %d reblock-dirs %s",
1081 snapshots_path, arg2, path);
1082 if (VerboseOpt == 0) {
1088 * Do not reblock all the data in normal mode.
1091 "hammer -c %s/.reblock-3.cycle -t %d reblock-data %s 95",
1092 snapshots_path, arg2, path);
1093 if (VerboseOpt == 0)
1099 cleanup_recopy(const char *path, const char *snapshots_path,
1100 int arg1 __unused, int arg2)
1102 if (VerboseOpt == 0) {
1107 "hammer -c %s/.recopy-1.cycle -t %d reblock-btree %s",
1108 snapshots_path, arg2, path);
1109 if (VerboseOpt == 0) {
1114 "hammer -c %s/.recopy-2.cycle -t %d reblock-inodes %s",
1115 snapshots_path, arg2, path);
1116 if (VerboseOpt == 0) {
1121 "hammer -c %s/.recopy-4.cycle -t %d reblock-dirs %s",
1122 snapshots_path, arg2, path);
1123 if (VerboseOpt == 0) {
1128 "hammer -c %s/.recopy-3.cycle -t %d reblock-data %s",
1129 snapshots_path, arg2, path);
1130 if (VerboseOpt == 0)
1137 runcmd(int *resp, const char *ctl, ...)
1149 * Generate the command
1152 vasprintf(&cmd, ctl, va);
1155 printf(" %s\n", cmd);
1158 * Break us down into arguments. We do not just use system() here
1159 * because it blocks SIGINT and friends.
1163 av = malloc(sizeof(char *) * nmax);
1165 for (arg = strtok(cmd, WS); arg; arg = strtok(NULL, WS)) {
1166 if (n == nmax - 1) {
1168 av = realloc(av, sizeof(char *) * nmax);
1178 if ((pid = fork()) == 0) {
1179 if (VerboseOpt < 2) {
1180 int fd = open("/dev/null", O_RDWR);
1186 } else if (pid < 0) {
1191 while (waitpid(pid, &status, 0) != pid)
1193 res = WEXITSTATUS(status);