Project

General

Profile

Bug #2759 ยป cmd_dedup01.diff

tuxillo, 01/07/2015 04:14 PM

View differences:

sbin/hammer/cmd_dedup.c
101 101
#define DEDUP_PASS2	0x0001 /* process_btree_elm() mode */
102 102

  
103 103
static int SigInfoFlag;
104
static int SigAlrmFlag;
104 105
static int64_t DedupDataReads;
105 106
static int64_t DedupCurrentRecords;
106 107
static int64_t DedupTotalRecords;
......
254 255
	struct dedup_entry *de;
255 256
	struct sha_dedup_entry *sha_de;
256 257
	struct pass2_dedup_entry *pass2_de;
258
	char *tmp;
257 259
	char buf[8];
260
	int needfree = 0;
258 261

  
259 262
	if (TimeoutOpt > 0)
260 263
		alarm(TimeoutOpt);
......
267 270
	glob_fd = getpfs(&glob_pfs, av[0]);
268 271

  
269 272
	/*
273
	 * A cycle file is _required_ for resuming dedup after the timeout
274
	 * specified with -t has expired. If no -c option, then place a
275
	 * .dedup.cycle file either in the PFS snapshots directory or in
276
	 * the default snapshots directory.
277
	 */
278
	if (!CyclePath) {
279
		if (glob_pfs.ondisk->snapshots[0] != '/')
280
			asprintf(&tmp, "%s/%s/.dedup.cycle",
281
			    SNAPSHOTS_BASE, av[0]);
282
		else
283
			asprintf(&tmp, "%s/.dedup.cycle",
284
			    glob_pfs.ondisk->snapshots);
285
		CyclePath = tmp;
286
		needfree = 1;
287
	}
288

  
289
	/*
270 290
	 * Pre-pass to cache the btree
271 291
	 */
272 292
	scan_pfs(av[0], count_btree_elm, "pre-pass ");
......
333 353
	relpfs(glob_fd, &glob_pfs);
334 354

  
335 355
	humanize_unsigned(buf, sizeof(buf), dedup_ref_size, "B", 1024);
336
	printf("Dedup ratio = %.2f\n"
356
	printf("Dedup ratio = %.2f (in this run)\n"
337 357
	       "    %8s referenced\n",
338 358
	       ((dedup_alloc_size != 0) ?
339 359
			(double)dedup_ref_size / dedup_alloc_size : 0),
......
354 374
               (intmax_t)dedup_successes_count,
355 375
               (intmax_t)dedup_successes_bytes
356 376
	);
377

  
378
	/* Once completed remove cycle file */
379
	hammer_reset_cycle();
380

  
381
	/* We don't want to mess up with other directives */
382
	if (needfree) {
383
		free(tmp);
384
		CyclePath = NULL;
385
	}
357 386
}
358 387

  
359 388
static int
......
814 843
}
815 844

  
816 845
static void
846
sigAlrm(int signo __unused)
847
{
848
	SigAlrmFlag = 1;
849
}
850

  
851
static void
817 852
sigInfo(int signo __unused)
818 853
{
819 854
	SigInfoFlag = 1;
......
834 869
	DedupDataReads = 0;
835 870
	DedupCurrentRecords = 0;
836 871
	signal(SIGINFO, sigInfo);
872
	signal(SIGALRM, sigAlrm);
837 873

  
874
	/*
875
	 * Deduplication happens per element so hammer(8) is in full
876
	 * control of the ioctl()s to actually perform it. SIGALRM
877
	 * needs to be handled within hammer(8) but a checkpoint
878
	 * is needed for resuming. Use cycle file for that.
879
	 *
880
	 * Try to obtain the previous obj_id from the cycle file and
881
	 * if not available just start from the beginning.
882
	 */
838 883
	bzero(&mirror, sizeof(mirror));
839 884
	hammer_key_beg_init(&mirror.key_beg);
885
	hammer_get_cycle(&mirror.key_beg, &mirror.tid_beg);
886

  
887
	if (mirror.key_beg.obj_id != (int64_t)HAMMER_MIN_OBJID) {
888
		if (VerboseOpt)
889
			fprintf(stderr, "%s: mirror-read: Resuming at object %016jx\n",
890
			    id, (uintmax_t)mirror.key_beg.obj_id);
891
	}
892

  
840 893
	hammer_key_end_init(&mirror.key_end);
841 894

  
842 895
	mirror.tid_beg = glob_pfs.ondisk->sync_beg_tid;
......
905 958
			}
906 959
		}
907 960
		mirror.key_beg = mirror.key_cur;
908
		if (DidInterrupt) {
909
			fprintf(stderr, "Interrupted\n");
961
		if (DidInterrupt || SigAlrmFlag) {
962
			if (VerboseOpt)
963
				fprintf(stderr, "%s\n",
964
				    (DidInterrupt ? "Interrupted" : "Timeout"));
965
			hammer_set_cycle(&mirror.key_cur, mirror.tid_beg);
966
			if (VerboseOpt)
967
				fprintf(stderr, "Cyclefile %s updated for "
968
				    "continuation\n", CyclePath);
910 969
			exit(1);
911 970
		}
912 971
		if (SigInfoFlag) {
......
938 997
	} while (mirror.count != 0);
939 998

  
940 999
	signal(SIGINFO, SIG_IGN);
1000
	signal(SIGALRM, SIG_IGN);
941 1001

  
942 1002
	free(buf);
943 1003
}
    (1-1/1)