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_mirror.c,v 1.8 2008/07/12 02:48:46 dillon Exp $
39 #define SERIALBUF_SIZE (512 * 1024)
41 static int read_mrecords(int fd, char *buf, u_int size,
42 hammer_ioc_mrecord_head_t pickup);
43 static hammer_ioc_mrecord_any_t read_mrecord(int fdin, int *errorp,
44 hammer_ioc_mrecord_head_t pickup);
45 static void write_mrecord(int fdout, u_int32_t type,
46 hammer_ioc_mrecord_any_t mrec, int bytes);
47 static void generate_mrec_header(int fd, int fdout, int pfs_id,
48 hammer_tid_t *tid_begp, hammer_tid_t *tid_endp);
49 static void validate_mrec_header(int fd, int fdin, int is_target, int pfs_id,
50 hammer_tid_t *tid_begp, hammer_tid_t *tid_endp);
51 static void update_pfs_snapshot(int fd, hammer_tid_t snapshot_tid, int pfs_id);
52 static void mirror_usage(int code);
55 * Generate a mirroring data stream from the specific source over the
56 * entire key range, but restricted to the specified transaction range.
58 * The HAMMER VFS does most of the work, we add a few new mrecord
59 * types to negotiate the TID ranges and verify that the entire
60 * stream made it to the destination.
63 hammer_cmd_mirror_read(char **av, int ac)
65 struct hammer_ioc_mirror_rw mirror;
66 struct hammer_ioc_pseudofs_rw pfs;
67 union hammer_ioc_mrecord_any mrec_tmp;
68 hammer_ioc_mrecord_any_t mrec;
69 hammer_tid_t sync_tid;
70 const char *filesystem;
71 char *buf = malloc(SERIALBUF_SIZE);
76 time_t base_t = time(NULL);
82 bzero(&mirror, sizeof(mirror));
83 hammer_key_beg_init(&mirror.key_beg);
84 hammer_key_end_init(&mirror.key_end);
86 fd = getpfs(&pfs, filesystem);
89 * In 2-way mode the target will send us a PFS info packet
90 * first. Use the target's current snapshot TID as our default
95 validate_mrec_header(fd, 0, 0, pfs.pfs_id,
96 NULL, &mirror.tid_beg);
99 * Write out the PFS header, tid_beg will be updated if our PFS
100 * has a larger begin sync. tid_end is set to the latest source
101 * TID whos flush cycle has completed.
103 generate_mrec_header(fd, 1, pfs.pfs_id,
104 &mirror.tid_beg, &mirror.tid_end);
107 * A cycle file overrides the beginning TID
109 hammer_get_cycle(&mirror.key_beg, &mirror.tid_beg);
112 mirror.tid_beg = strtoull(av[1], NULL, 0);
114 fprintf(stderr, "mirror-read: Mirror from %016llx to %016llx\n",
115 mirror.tid_beg, mirror.tid_end);
116 if (mirror.key_beg.obj_id != (int64_t)HAMMER_MIN_OBJID) {
117 fprintf(stderr, "mirror-read: Resuming at object %016llx\n",
118 mirror.key_beg.obj_id);
122 * Write out bulk records
125 mirror.size = SERIALBUF_SIZE;
129 mirror.pfs_id = pfs.pfs_id;
130 mirror.shared_uuid = pfs.ondisk->shared_uuid;
131 if (ioctl(fd, HAMMERIOC_MIRROR_READ, &mirror) < 0) {
132 fprintf(stderr, "Mirror-read %s failed: %s\n",
133 filesystem, strerror(errno));
136 if (mirror.head.flags & HAMMER_IOC_HEAD_ERROR) {
138 "Mirror-read %s fatal error %d\n",
139 filesystem, mirror.head.error);
143 n = write(1, mirror.ubuf, mirror.count);
144 if (n != mirror.count) {
145 fprintf(stderr, "Mirror-read %s failed: "
151 mirror.key_beg = mirror.key_cur;
153 (unsigned)(time(NULL) - base_t) > (unsigned)TimeoutOpt) {
155 "Mirror-read %s interrupted by timer at"
158 mirror.key_cur.obj_id);
162 } while (mirror.count != 0);
165 * Write out the termination sync record
167 write_mrecord(1, HAMMER_MREC_TYPE_SYNC,
168 &mrec_tmp, sizeof(mrec_tmp.sync));
171 * If the -2 option was given (automatic when doing mirror-copy),
172 * a two-way pipe is assumed and we expect a response mrec from
176 mrec = read_mrecord(0, &error, NULL);
178 mrec->head.type != HAMMER_MREC_TYPE_UPDATE ||
179 mrec->head.rec_size != sizeof(mrec->update)) {
180 fprintf(stderr, "mirror_read: Did not get final "
181 "acknowledgement packet from target\n");
186 hammer_set_cycle(&mirror.key_cur, mirror.tid_beg);
187 fprintf(stderr, "Cyclefile %s updated for continuation\n", CyclePath);
190 sync_tid = mrec->update.tid;
192 hammer_key_beg_init(&mirror.key_beg);
193 hammer_set_cycle(&mirror.key_beg, sync_tid);
194 fprintf(stderr, "Cyclefile %s updated to 0x%016llx\n",
195 CyclePath, sync_tid);
197 fprintf(stderr, "Source can update synctid "
202 } else if (CyclePath) {
203 /* NOTE! mirror.tid_beg cannot be updated */
204 fprintf(stderr, "Warning: cycle file (-c option) cannot be "
205 "fully updated unless you use mirror-copy\n");
206 hammer_set_cycle(&mirror.key_beg, mirror.tid_beg);
208 fprintf(stderr, "Mirror-read %s succeeded\n", filesystem);
212 * Pipe the mirroring data stream on stdin to the HAMMER VFS, adding
213 * some additional packet types to negotiate TID ranges and to verify
214 * completion. The HAMMER VFS does most of the work.
216 * It is important to note that the mirror.key_{beg,end} range must
217 * match the ranged used by the original. For now both sides use
218 * range the entire key space.
220 * It is even more important that the records in the stream conform
221 * to the TID range also supplied in the stream. The HAMMER VFS will
222 * use the REC, PASS, and SKIP record types to track the portions of
223 * the B-Tree being scanned in order to be able to proactively delete
224 * records on the target within those active areas that are not mentioned
227 * The mirror.key_cur field is used by the VFS to do this tracking. It
228 * must be initialized to key_beg but then is persistently updated by
229 * the HAMMER VFS on each successive ioctl() call. If you blow up this
230 * field you will blow up the mirror target, possibly to the point of
231 * deleting everything. As a safety measure the HAMMER VFS simply marks
232 * the records that the source has destroyed as deleted on the target,
233 * and normal pruning operations will deal with their final disposition
234 * at some later time.
237 hammer_cmd_mirror_write(char **av, int ac)
239 struct hammer_ioc_mirror_rw mirror;
240 const char *filesystem;
241 char *buf = malloc(SERIALBUF_SIZE);
242 struct hammer_ioc_pseudofs_rw pfs;
243 struct hammer_ioc_mrecord_head pickup;
244 struct hammer_ioc_synctid synctid;
245 union hammer_ioc_mrecord_any mrec_tmp;
246 hammer_ioc_mrecord_any_t mrec;
254 bzero(&mirror, sizeof(mirror));
255 hammer_key_beg_init(&mirror.key_beg);
256 hammer_key_end_init(&mirror.key_end);
257 mirror.key_end = mirror.key_beg;
259 fd = getpfs(&pfs, filesystem);
262 * In two-way mode the target writes out a PFS packet first.
263 * The source uses our tid_end as its tid_beg by default,
264 * picking up where it left off.
268 generate_mrec_header(fd, 1, pfs.pfs_id,
269 &mirror.tid_beg, &mirror.tid_end);
273 * Read and process the PFS header. The source informs us of
274 * the TID range the stream represents.
276 validate_mrec_header(fd, 0, 1, pfs.pfs_id,
277 &mirror.tid_beg, &mirror.tid_end);
280 mirror.size = SERIALBUF_SIZE;
282 pickup.signature = 0;
286 * Read and process bulk records (REC, PASS, and SKIP types).
288 * On your life, do NOT mess with mirror.key_cur or your mirror
289 * target may become history.
293 mirror.pfs_id = pfs.pfs_id;
294 mirror.shared_uuid = pfs.ondisk->shared_uuid;
295 mirror.size = read_mrecords(0, buf, SERIALBUF_SIZE, &pickup);
296 if (mirror.size <= 0)
298 if (ioctl(fd, HAMMERIOC_MIRROR_WRITE, &mirror) < 0) {
299 fprintf(stderr, "Mirror-write %s failed: %s\n",
300 filesystem, strerror(errno));
303 if (mirror.head.flags & HAMMER_IOC_HEAD_ERROR) {
305 "Mirror-write %s fatal error %d\n",
306 filesystem, mirror.head.error);
310 if (mirror.head.flags & HAMMER_IOC_HEAD_INTR) {
312 "Mirror-write %s interrupted by timer at"
315 mirror.key_cur.obj_id);
322 * Read and process the termination sync record.
324 mrec = read_mrecord(0, &error, &pickup);
326 mrec->head.type != HAMMER_MREC_TYPE_SYNC ||
327 mrec->head.rec_size != sizeof(mrec->sync)) {
328 fprintf(stderr, "Mirror-write %s: Did not get termination "
329 "sync record, or rec_size is wrong rt=%d\n",
330 filesystem, mrec->head.type);
336 * Update the PFS info on the target so the user has visibility
337 * into the new snapshot.
339 update_pfs_snapshot(fd, mirror.tid_end, pfs.pfs_id);
342 * Sync the target filesystem
344 bzero(&synctid, sizeof(synctid));
345 synctid.op = HAMMER_SYNCTID_SYNC2;
346 ioctl(fd, HAMMERIOC_SYNCTID, &synctid);
348 fprintf(stderr, "Mirror-write %s: succeeded\n", filesystem);
351 * Report back to the originator.
354 mrec_tmp.update.tid = mirror.tid_end;
355 write_mrecord(1, HAMMER_MREC_TYPE_UPDATE,
356 &mrec_tmp, sizeof(mrec_tmp.update));
358 printf("Source can update synctid to 0x%016llx\n",
364 hammer_cmd_mirror_dump(void)
366 char *buf = malloc(SERIALBUF_SIZE);
367 struct hammer_ioc_mrecord_head pickup;
368 hammer_ioc_mrecord_any_t mrec;
375 * Read and process the PFS header
377 pickup.signature = 0;
380 mrec = read_mrecord(0, &error, &pickup);
383 * Read and process bulk records
386 size = read_mrecords(0, buf, SERIALBUF_SIZE, &pickup);
390 while (offset < size) {
391 mrec = (void *)((char *)buf + offset);
392 bytes = HAMMER_HEAD_DOALIGN(mrec->head.rec_size);
393 if (offset + bytes > size) {
394 fprintf(stderr, "Misaligned record\n");
398 switch(mrec->head.type) {
399 case HAMMER_MREC_TYPE_REC:
400 printf("Record obj=%016llx key=%016llx "
402 mrec->rec.leaf.base.obj_id,
403 mrec->rec.leaf.base.key,
404 mrec->rec.leaf.base.rec_type,
405 mrec->rec.leaf.base.obj_type);
406 printf(" tids %016llx:%016llx data=%d\n",
407 mrec->rec.leaf.base.create_tid,
408 mrec->rec.leaf.base.delete_tid,
409 mrec->rec.leaf.data_len);
411 case HAMMER_MREC_TYPE_PASS:
412 printf("Pass obj=%016llx key=%016llx "
414 mrec->rec.leaf.base.obj_id,
415 mrec->rec.leaf.base.key,
416 mrec->rec.leaf.base.rec_type,
417 mrec->rec.leaf.base.obj_type);
418 printf(" tids %016llx:%016llx data=%d\n",
419 mrec->rec.leaf.base.create_tid,
420 mrec->rec.leaf.base.delete_tid,
421 mrec->rec.leaf.data_len);
423 case HAMMER_MREC_TYPE_SKIP:
424 printf("Skip obj=%016llx key=%016llx rt=%02x to\n"
425 " obj=%016llx key=%016llx rt=%02x\n",
426 mrec->skip.skip_beg.obj_id,
427 mrec->skip.skip_beg.key,
428 mrec->skip.skip_beg.rec_type,
429 mrec->skip.skip_end.obj_id,
430 mrec->skip.skip_end.key,
431 mrec->skip.skip_end.rec_type);
440 * Read and process the termination sync record.
442 mrec = read_mrecord(0, &error, &pickup);
443 if (mrec == NULL || mrec->head.type != HAMMER_MREC_TYPE_SYNC) {
444 fprintf(stderr, "Mirror-dump: Did not get termination "
450 hammer_cmd_mirror_copy(char **av, int ac)
473 if ((pid1 = fork()) == 0) {
478 if ((ptr = strchr(av[0], ':')) != NULL) {
483 xav[xac++] = "hammer";
488 snprintf(tbuf, sizeof(tbuf), "%d", TimeoutOpt);
492 xav[xac++] = "mirror-read";
495 execv("/usr/bin/ssh", (void *)xav);
497 hammer_cmd_mirror_read(av, 1);
507 if ((pid2 = fork()) == 0) {
512 if ((ptr = strchr(av[1], ':')) != NULL) {
517 xav[xac++] = "hammer";
521 xav[xac++] = "mirror-write";
524 execv("/usr/bin/ssh", (void *)xav);
526 hammer_cmd_mirror_write(av + 1, 1);
535 while (waitpid(pid1, NULL, 0) <= 0)
537 while (waitpid(pid2, NULL, 0) <= 0)
542 * Read and return multiple mrecords
545 read_mrecords(int fd, char *buf, u_int size, hammer_ioc_mrecord_head_t pickup)
547 hammer_ioc_mrecord_any_t mrec;
554 while (size - count >= HAMMER_MREC_HEADSIZE) {
556 * Cached the record header in case we run out of buffer
560 if (pickup->signature == 0) {
561 for (n = 0; n < HAMMER_MREC_HEADSIZE; n += i) {
562 i = read(fd, (char *)pickup + n,
563 HAMMER_MREC_HEADSIZE - n);
569 if (n != HAMMER_MREC_HEADSIZE) {
570 fprintf(stderr, "read_mrecords: short read on pipe\n");
574 if (pickup->signature != HAMMER_IOC_MIRROR_SIGNATURE) {
575 fprintf(stderr, "read_mrecords: malformed record on pipe, bad signature\n");
579 if (pickup->rec_size < HAMMER_MREC_HEADSIZE ||
580 pickup->rec_size > sizeof(*mrec) + HAMMER_XBUFSIZE) {
581 fprintf(stderr, "read_mrecords: malformed record on pipe, illegal rec_size\n");
586 * Stop if we have insufficient space for the record and data.
588 bytes = HAMMER_HEAD_DOALIGN(pickup->rec_size);
589 if (size - count < bytes)
593 * Stop if the record type is not a REC or a SKIP (the only
594 * two types the ioctl supports. Other types are used only
595 * by the userland protocol).
597 if (pickup->type != HAMMER_MREC_TYPE_REC &&
598 pickup->type != HAMMER_MREC_TYPE_SKIP &&
599 pickup->type != HAMMER_MREC_TYPE_PASS) {
604 * Read the remainder and clear the pickup signature.
606 for (n = HAMMER_MREC_HEADSIZE; n < bytes; n += i) {
607 i = read(fd, buf + count + n, bytes - n);
612 fprintf(stderr, "read_mrecords: short read on pipe\n");
616 bcopy(pickup, buf + count, HAMMER_MREC_HEADSIZE);
617 pickup->signature = 0;
619 mrec = (void *)(buf + count);
622 * Validate the completed record
624 if (mrec->head.rec_crc !=
625 crc32((char *)mrec + HAMMER_MREC_CRCOFF,
626 mrec->head.rec_size - HAMMER_MREC_CRCOFF)) {
627 fprintf(stderr, "read_mrecords: malformed record "
628 "on pipe, bad crc\n");
633 * If its a B-Tree record validate the data crc
635 if (mrec->head.type == HAMMER_MREC_TYPE_REC) {
636 if (mrec->head.rec_size <
637 sizeof(mrec->rec) + mrec->rec.leaf.data_len) {
639 "read_mrecords: malformed record on "
640 "pipe, illegal element data_len\n");
643 if (mrec->rec.leaf.data_len &&
644 mrec->rec.leaf.data_offset &&
645 hammer_crc_test_leaf(&mrec->rec + 1, &mrec->rec.leaf) == 0) {
647 "read_mrecords: data_crc did not "
648 "match data! obj=%016llx key=%016llx\n",
649 mrec->rec.leaf.base.obj_id,
650 mrec->rec.leaf.base.key);
652 "continuing, but there are problems\n");
661 * Read and return a single mrecord.
664 hammer_ioc_mrecord_any_t
665 read_mrecord(int fdin, int *errorp, hammer_ioc_mrecord_head_t pickup)
667 hammer_ioc_mrecord_any_t mrec;
668 struct hammer_ioc_mrecord_head mrechd;
673 if (pickup && pickup->type != 0) {
675 pickup->signature = 0;
677 n = HAMMER_MREC_HEADSIZE;
680 * Read in the PFSD header from the sender.
682 for (n = 0; n < HAMMER_MREC_HEADSIZE; n += i) {
683 i = read(fdin, (char *)&mrechd + n, HAMMER_MREC_HEADSIZE - n);
688 *errorp = 0; /* EOF */
691 if (n != HAMMER_MREC_HEADSIZE) {
692 fprintf(stderr, "short read of mrecord header\n");
697 if (mrechd.signature != HAMMER_IOC_MIRROR_SIGNATURE) {
698 fprintf(stderr, "read_mrecord: bad signature\n");
702 bytes = HAMMER_HEAD_DOALIGN(mrechd.rec_size);
703 assert(bytes >= sizeof(mrechd));
704 mrec = malloc(bytes);
708 i = read(fdin, (char *)mrec + n, bytes - n);
714 fprintf(stderr, "read_mrecord: short read on payload\n");
718 if (mrec->head.rec_crc !=
719 crc32((char *)mrec + HAMMER_MREC_CRCOFF,
720 mrec->head.rec_size - HAMMER_MREC_CRCOFF)) {
721 fprintf(stderr, "read_mrecord: bad CRC\n");
731 write_mrecord(int fdout, u_int32_t type, hammer_ioc_mrecord_any_t mrec,
734 char zbuf[HAMMER_HEAD_ALIGN];
737 pad = HAMMER_HEAD_DOALIGN(bytes) - bytes;
739 assert(bytes >= (int)sizeof(mrec->head));
740 bzero(&mrec->head, sizeof(mrec->head));
741 mrec->head.signature = HAMMER_IOC_MIRROR_SIGNATURE;
742 mrec->head.type = type;
743 mrec->head.rec_size = bytes;
744 mrec->head.rec_crc = crc32((char *)mrec + HAMMER_MREC_CRCOFF,
745 bytes - HAMMER_MREC_CRCOFF);
746 if (write(fdout, mrec, bytes) != bytes) {
747 fprintf(stderr, "write_mrecord: error %d (%s)\n",
748 errno, strerror(errno));
753 if (write(fdout, zbuf, pad) != pad) {
754 fprintf(stderr, "write_mrecord: error %d (%s)\n",
755 errno, strerror(errno));
762 * Generate a mirroring header with the pfs information of the
763 * originating filesytem.
766 generate_mrec_header(int fd, int fdout, int pfs_id,
767 hammer_tid_t *tid_begp, hammer_tid_t *tid_endp)
769 struct hammer_ioc_pseudofs_rw pfs;
770 union hammer_ioc_mrecord_any mrec_tmp;
772 bzero(&pfs, sizeof(pfs));
773 bzero(&mrec_tmp, sizeof(mrec_tmp));
775 pfs.ondisk = &mrec_tmp.pfs.pfsd;
776 pfs.bytes = sizeof(mrec_tmp.pfs.pfsd);
777 if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) != 0) {
778 fprintf(stderr, "mirror-read: not a HAMMER fs/pseudofs!\n");
781 if (pfs.version != HAMMER_IOC_PSEUDOFS_VERSION) {
782 fprintf(stderr, "mirror-read: HAMMER pfs version mismatch!\n");
787 * sync_beg_tid - lowest TID on source after which a full history
790 * sync_end_tid - highest fully synchronized TID from source.
792 if (tid_begp && *tid_begp < mrec_tmp.pfs.pfsd.sync_beg_tid)
793 *tid_begp = mrec_tmp.pfs.pfsd.sync_beg_tid;
795 *tid_endp = mrec_tmp.pfs.pfsd.sync_end_tid;
796 mrec_tmp.pfs.version = pfs.version;
797 write_mrecord(fdout, HAMMER_MREC_TYPE_PFSD,
798 &mrec_tmp, sizeof(mrec_tmp.pfs));
802 * Validate the pfs information from the originating filesystem
803 * against the target filesystem. shared_uuid must match.
806 validate_mrec_header(int fd, int fdin, int is_target, int pfs_id,
807 hammer_tid_t *tid_begp, hammer_tid_t *tid_endp)
809 struct hammer_ioc_pseudofs_rw pfs;
810 struct hammer_pseudofs_data pfsd;
811 hammer_ioc_mrecord_any_t mrec;
815 * Get the PFSD info from the target filesystem.
817 bzero(&pfs, sizeof(pfs));
818 bzero(&pfsd, sizeof(pfsd));
821 pfs.bytes = sizeof(pfsd);
822 if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) != 0) {
823 fprintf(stderr, "mirror-write: not a HAMMER fs/pseudofs!\n");
826 if (pfs.version != HAMMER_IOC_PSEUDOFS_VERSION) {
827 fprintf(stderr, "mirror-write: HAMMER pfs version mismatch!\n");
831 mrec = read_mrecord(fdin, &error, NULL);
834 fprintf(stderr, "validate_mrec_header: short read\n");
837 if (mrec->head.type != HAMMER_MREC_TYPE_PFSD) {
838 fprintf(stderr, "validate_mrec_header: did not get expected "
839 "PFSD record type\n");
842 if (mrec->head.rec_size != sizeof(mrec->pfs)) {
843 fprintf(stderr, "validate_mrec_header: unexpected payload "
847 if (mrec->pfs.version != pfs.version) {
848 fprintf(stderr, "validate_mrec_header: Version mismatch\n");
853 * Whew. Ok, is the read PFS info compatible with the target?
855 if (bcmp(&mrec->pfs.pfsd.shared_uuid, &pfsd.shared_uuid,
856 sizeof(pfsd.shared_uuid)) != 0) {
858 "mirror-write: source and target have "
859 "different shared_uuid's!\n");
863 (pfsd.mirror_flags & HAMMER_PFSD_SLAVE) == 0) {
864 fprintf(stderr, "mirror-write: target must be in slave mode\n");
868 *tid_begp = mrec->pfs.pfsd.sync_beg_tid;
870 *tid_endp = mrec->pfs.pfsd.sync_end_tid;
875 update_pfs_snapshot(int fd, hammer_tid_t snapshot_tid, int pfs_id)
877 struct hammer_ioc_pseudofs_rw pfs;
878 struct hammer_pseudofs_data pfsd;
880 bzero(&pfs, sizeof(pfs));
881 bzero(&pfsd, sizeof(pfsd));
884 pfs.bytes = sizeof(pfsd);
885 if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) != 0) {
886 perror("update_pfs_snapshot (read)");
889 if (pfsd.sync_end_tid != snapshot_tid) {
890 pfsd.sync_end_tid = snapshot_tid;
891 if (ioctl(fd, HAMMERIOC_SET_PSEUDOFS, &pfs) != 0) {
892 perror("update_pfs_snapshot (rewrite)");
900 mirror_usage(int code)
903 "hammer mirror-read <filesystem>\n"
904 "hammer mirror-write <filesystem>\n"
905 "hammer mirror-dump\n"
906 "hammer mirror-copy [[user@]host:]fs [[user@]host:]fs\n"