Esempio n. 1
0
void
hammer_cmd_pseudofs_status(char **av, int ac)
{
	struct hammer_ioc_pseudofs_rw pfs;
	int i;
	int fd;

	if (ac == 0)
		pseudofs_usage(1);

	for (i = 0; i < ac; ++i) {
		printf("%s\t", av[i]);
		fd = getpfs(&pfs, av[i]);
		if (fd < 0 || ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) < 0) {
			printf("Not a HAMMER root\n");
		} else {
			printf("PFS #%d {\n", pfs.pfs_id);
			dump_pfsd(pfs.ondisk, fd);
			printf("}\n");
		}
		if (fd >= 0)
			close(fd);
		if (pfs.ondisk)
			free(pfs.ondisk);
	}
}
Esempio n. 2
0
static void
print_pfs_status(char *path)
{
	struct hammer_ioc_pseudofs_rw pfs;
	int fd;

	fd = getpfs(&pfs, path);
	printf("%s\t", path);
	if (fd < 0 || ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) < 0) {
		printf("Invalid PFS path %s\n", path);
	} else {
		printf("PFS#%d {\n", pfs.pfs_id);
		dump_pfsd(pfs.ondisk, fd);
		printf("}\n");
	}
	if (fd >= 0)
		close(fd);
	if (pfs.ondisk)
		free(pfs.ondisk);
	relpfs(fd, &pfs);
}
Esempio n. 3
0
void
hammer_cmd_pseudofs_update(char **av, int ac)
{
	struct hammer_ioc_pseudofs_rw pfs;
	int fd;

	if (ac == 0)
		pseudofs_usage(1);
	bzero(&pfs, sizeof(pfs));
	fd = getpfs(&pfs, av[0]);

	printf("%s\n", av[0]);
	fflush(stdout);

	if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) == 0) {
		parse_pfsd_options(av + 1, ac - 1, pfs.ondisk);
		if ((pfs.ondisk->mirror_flags & HAMMER_PFSD_SLAVE) &&
		    pfs.pfs_id == 0) {
			printf("The real mount point cannot be made a PFS "
			       "slave, only PFS sub-directories can be made "
			       "slaves\n");
			exit(1);
		}
		pfs.bytes = sizeof(*pfs.ondisk);
		if (ioctl(fd, HAMMERIOC_SET_PSEUDOFS, &pfs) == 0) {
			if (ioctl(fd, HAMMERIOC_GET_PSEUDOFS, &pfs) == 0) {
				dump_pfsd(pfs.ondisk, fd);
			} else {
				printf("Unable to retrieve pfs configuration "
					"after successful update: %s\n",
					strerror(errno));
				exit(1);
			}
		} else {
			printf("Unable to adjust pfs configuration: %s\n",
				strerror(errno));
			exit(1);
		}
	}
}
Esempio n. 4
0
void
hammer_cmd_mirror_dump(char **av, int ac)
{
	char *buf = malloc(SERIALBUF_SIZE);
	struct hammer_ioc_mrecord_head pickup;
	hammer_ioc_mrecord_any_t mrec;
	int error;
	int size;
	int offset;
	int bytes;
	int header_only = 0;

	if (ac == 1 && strcmp(*av, "header") == 0)
		header_only = 1;
	else if (ac != 0)
		mirror_usage(1);

	/*
	 * Read and process the PFS header
	 */
	pickup.signature = 0;
	pickup.type = 0;

	mrec = read_mrecord(0, &error, &pickup);

	/*
	 * Dump the PFS header. mirror-dump takes its input from the output
	 * of a mirror-read so getpfs() can't be used to get a fd to be passed
	 * to dump_pfsd().
	 */
	if (header_only && mrec != NULL) {
		dump_pfsd(&mrec->pfs.pfsd, -1);
		free(mrec);
		free(buf);
		return;
	}
	free(mrec);

again:
	/*
	 * Read and process bulk records
	 */
	for (;;) {
		size = read_mrecords(0, buf, SERIALBUF_SIZE, &pickup);
		if (size <= 0)
			break;
		offset = 0;
		while (offset < size) {
			mrec = (void *)((char *)buf + offset);
			bytes = HAMMER_HEAD_DOALIGN(mrec->head.rec_size);
			if (offset + bytes > size) {
				fprintf(stderr, "Misaligned record\n");
				exit(1);
			}

			switch(mrec->head.type & HAMMER_MRECF_TYPE_MASK) {
			case HAMMER_MREC_TYPE_REC_BADCRC:
			case HAMMER_MREC_TYPE_REC:
				printf("Record lo=%08x obj=%016jx key=%016jx "
				       "rt=%02x ot=%02x",
				        mrec->rec.leaf.base.localization,
					(uintmax_t)mrec->rec.leaf.base.obj_id,
					(uintmax_t)mrec->rec.leaf.base.key,
					mrec->rec.leaf.base.rec_type,
					mrec->rec.leaf.base.obj_type);
				if (mrec->head.type ==
				    HAMMER_MREC_TYPE_REC_BADCRC) {
					printf(" (BAD CRC)");
				}
				printf("\n");
				printf("       tids %016jx:%016jx data=%d\n",
				    (uintmax_t)mrec->rec.leaf.base.create_tid,
				    (uintmax_t)mrec->rec.leaf.base.delete_tid,
				    mrec->rec.leaf.data_len);
				break;
			case HAMMER_MREC_TYPE_PASS:
				printf("Pass   lo=%08x obj=%016jx key=%016jx "
				       "rt=%02x ot=%02x\n",
				        mrec->rec.leaf.base.localization,
					(uintmax_t)mrec->rec.leaf.base.obj_id,
					(uintmax_t)mrec->rec.leaf.base.key,
					mrec->rec.leaf.base.rec_type,
					mrec->rec.leaf.base.obj_type);
				printf("       tids %016jx:%016jx data=%d\n",
				    (uintmax_t)mrec->rec.leaf.base.create_tid,
				    (uintmax_t)mrec->rec.leaf.base.delete_tid,
					mrec->rec.leaf.data_len);
				break;
			case HAMMER_MREC_TYPE_SKIP:
				printf("Skip   lo=%08x obj=%016jx key=%016jx rt=%02x to\n"
				       "       lo=%08x obj=%016jx key=%016jx rt=%02x\n",
				       mrec->skip.skip_beg.localization,
				       (uintmax_t)mrec->skip.skip_beg.obj_id,
				       (uintmax_t)mrec->skip.skip_beg.key,
				       mrec->skip.skip_beg.rec_type,
				       mrec->skip.skip_end.localization,
				       (uintmax_t)mrec->skip.skip_end.obj_id,
				       (uintmax_t)mrec->skip.skip_end.key,
				       mrec->skip.skip_end.rec_type);
			default:
				break;
			}
			offset += bytes;
		}
	}

	/*
	 * Read and process the termination sync record.
	 */
	mrec = read_mrecord(0, &error, &pickup);
	if (mrec == NULL ||
	    (mrec->head.type != HAMMER_MREC_TYPE_SYNC &&
	     mrec->head.type != HAMMER_MREC_TYPE_IDLE)) {
		fprintf(stderr, "Mirror-dump: Did not get termination "
				"sync record\n");
	}
	free(mrec);

	/*
	 * Continue with more batches until EOF.
	 */
	mrec = read_mrecord(0, &error, &pickup);
	if (mrec) {
		free(mrec);
		goto again;
	}
	free(buf);
}