Пример #1
0
int
libhammer_pfs_get_snapshots(libhammer_fsinfo_t fip, libhammer_pfsinfo_t pip)
{
	struct hammer_snapshot_data *snapdata = NULL;
	struct hammer_ioc_snapshot snap;
	libhammer_snapinfo_t sip;
	libhammer_pfsinfo_t pfs0;
	char *path = NULL;
	int ret = 0;
	int fd;
	u_int i;

	assert(pip != NULL);
	assert(fip != NULL);

	/*
	 * Still need a path to open so, when not mounted, try
	 * to figure out the PFS path access in order to open(2)
	 * Note that this will fail for slave PFS that were created
	 * with pfs-slave directive since they don't have any transaction
	 * recorded and nlookup can't find them. For those we simply
	 * return the error in the head structure of libhammer_pfsinfo_t
	 * for the caller to handle the situation.
	 */
	pfs0 = libhammer_get_first_pfs(fip);
	if (pip->mountedon == NULL)
		libhammer_pfs_canonical_path(pfs0->mountedon, pip, &path);
	else
		path = strdup(pip->mountedon);

	if (path == NULL || (fd = open(path, O_RDONLY)) < 0) {
		pip->head.error = errno;
		ret = -1;
		goto out;
	}

	bzero(&snap, sizeof(snap));

	/*
	 * Loop while there are snapshots returned from the ioctl(2) call.
	 *
	 * For more information on how the snapshots are returned
	 * to userland please check sys/vfs/hammer/hammer_ioctl.c
	 */
	do {
		if (ioctl(fd, HAMMERIOC_GET_SNAPSHOT, &snap) < 0) {
			pip->head.error = errno;
			ret = -1;
			close(fd);
			goto out;
		}
		for (i = 0; i < snap.count; i++) {
			snapdata = &snap.snaps[i];
			sip = _libhammer_malloc(sizeof(*sip));
			sip->tid = snapdata->tid;
			sip->ts = snapdata->ts;
			if (strlen(snapdata->label))
				sprintf(sip->label, "%s", snapdata->label);
			else
				sip->label[0] = '\0';
			TAILQ_INSERT_TAIL(&pip->list_snap, sip, entries);
			pip->snapcount++;
		}
	} while (snap.head.error == 0 && snap.count);
	close(fd);

out:
	if (path)
		free(path);

	return (ret);
}
Пример #2
0
void
show_info(char *path)
{
	libhammer_volinfo_t hvi;
	libhammer_pfsinfo_t pi, pi_first;
	int64_t	    usedbigblocks;
	int64_t	    usedbytes, rsvbytes;
	int64_t	    totalbytes, freebytes;
	int         error;
	char	    *fsid;
	char	    buf[6];
	u_int32_t   sc;

	fsid = NULL;
	usedbigblocks = 0;

	usedbytes = totalbytes = rsvbytes = freebytes = 0;
	sc = error = 0;

	hvi = libhammer_get_volinfo(path);
	if (hvi == NULL) {
		perror("libhammer_get_volinfo");
		exit(EXIT_FAILURE);
	}

	/* Find out the UUID strings */
	uuid_to_string(&hvi->vol_fsid, &fsid, NULL);

	/* Volume information */
	fprintf(stdout, "Volume identification\n");
	fprintf(stdout, "\tLabel               %s\n", hvi->vol_name);
	fprintf(stdout, "\tNo. Volumes         %d\n", hvi->nvolumes);
	fprintf(stdout, "\tFSID                %s\n", fsid);
	fprintf(stdout, "\tHAMMER Version      %d\n", hvi->version);

	/* Big blocks information */
	usedbigblocks = hvi->bigblocks - hvi->freebigblocks;

	fprintf(stdout, "Big block information\n");
	fprintf(stdout, "\tTotal      %10jd\n", (intmax_t)hvi->bigblocks);
	fprintf(stdout, "\tUsed       %10jd (%.2lf%%)\n"
			"\tReserved   %10jd (%.2lf%%)\n"
			"\tFree       %10jd (%.2lf%%)\n",
			(intmax_t)usedbigblocks,
			percent(usedbigblocks, hvi->bigblocks),
			(intmax_t)hvi->rsvbigblocks,
			percent(hvi->rsvbigblocks, hvi->bigblocks),
			(intmax_t)(hvi->freebigblocks - hvi->rsvbigblocks),
			percent(hvi->freebigblocks - hvi->rsvbigblocks,
				hvi->bigblocks));
	fprintf(stdout, "Space information\n");

	/* Space information */
	totalbytes = (hvi->bigblocks << HAMMER_LARGEBLOCK_BITS);
	usedbytes = (usedbigblocks << HAMMER_LARGEBLOCK_BITS);
	rsvbytes = (hvi->rsvbigblocks << HAMMER_LARGEBLOCK_BITS);
	freebytes = ((hvi->freebigblocks - hvi->rsvbigblocks)
	    << HAMMER_LARGEBLOCK_BITS);

	fprintf(stdout, "\tNo. Inodes %10jd\n", (intmax_t)hvi->inodes);
	humanize_number(buf, sizeof(buf)  - (totalbytes < 0 ? 0 : 1),
	    totalbytes, "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE | HN_B);
	fprintf(stdout, "\tTotal size     %6s (%jd bytes)\n",
	    buf, (intmax_t)totalbytes);

	humanize_number(buf, sizeof(buf)  - (usedbytes < 0 ? 0 : 1),
	    usedbytes, "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE | HN_B);
	fprintf(stdout, "\tUsed           %6s (%.2lf%%)\n", buf,
	    percent(usedbytes, totalbytes));

	humanize_number(buf, sizeof(buf)  - (rsvbytes < 0 ? 0 : 1),
	    rsvbytes, "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE | HN_B);
	fprintf(stdout, "\tReserved       %6s (%.2lf%%)\n", buf,
	    percent(rsvbytes, totalbytes));

	humanize_number(buf, sizeof(buf)  - (freebytes < 0 ? 0 : 1),
	    freebytes, "", HN_AUTOSCALE, HN_DECIMAL | HN_NOSPACE | HN_B);
	fprintf(stdout, "\tFree           %6s (%.2lf%%)\n", buf,
	    percent(freebytes, totalbytes));

	/* Pseudo-filesystem information */
	fprintf(stdout, "PFS information\n");
	fprintf(stdout, "\tPFS ID  Mode    Snaps  Mounted on\n");

	/* Iterate all the PFSs found */
	pi_first = libhammer_get_first_pfs(hvi);
	for (pi = pi_first; pi != NULL; pi = libhammer_get_next_pfs(pi)) {
		fprintf(stdout, "\t%6d  %-6s",
		    pi->pfs_id, (pi->ismaster ? "MASTER" : "SLAVE"));

		snprintf(buf, 6, "%d", pi->snapcount);
		fprintf(stdout, " %6s  ", (pi->head.error && pi->snapcount == 0) ? "-" : buf);

		if (pi->mountedon)
			fprintf(stdout, "%s", pi->mountedon);
		else
			fprintf(stdout, "not mounted");

		fprintf(stdout, "\n");
	}

	free(fsid);

	libhammer_free_volinfo(hvi);

}