コード例 #1
0
int
cmd_pfs_snapshot(const char *sel_path, const char *path, const char *label)
{
	hammer2_ioc_pfs_t pfs;
	int ecode = 0;
	int fd;
	char filename[HAMMER2_INODE_MAXNAME];
	char *xname;
	time_t t;
	struct tm *tp;

	if (path == NULL) {
		fd = hammer2_ioctl_handle(sel_path);
		xname = strdup("");
	} else {
		fd = open(path, O_RDONLY);
		if (fd < 0)
			fprintf(stderr, "Unable to open %s\n", path);
		if (strrchr(path, '/'))
			asprintf(&xname, ".%s", strrchr(path, '/') + 1);
		else if (*path)
			asprintf(&xname, ".%s", path);
		else
			xname = strdup("");
	}
	if (fd < 0)
		return 1;

	if (label == NULL) {
		time(&t);
		tp = localtime(&t);
		bzero(&pfs, sizeof(pfs));
		pfs.name_key = (hammer2_key_t)-1;
		if (ioctl(fd, HAMMER2IOC_PFS_GET, &pfs) < 0) {
			perror("ioctl");
		}
		snprintf(filename, sizeof(filename),
			 "%s%s.%04d%02d%02d.%02d%02d%02d",
			 pfs.name,
			 xname,
			 tp->tm_year + 1900,
			 tp->tm_mon + 1,
			 tp->tm_mday,
			 tp->tm_hour,
			 tp->tm_min,
			 tp->tm_sec);
		label = filename;
	}

	bzero(&pfs, sizeof(pfs));
	snprintf(pfs.name, sizeof(pfs.name), "%s", label);

	if (ioctl(fd, HAMMER2IOC_PFS_SNAPSHOT, &pfs) < 0) {
		perror("ioctl");
		ecode = 1;
	} else {
		printf("created snapshot %s\n", label);
	}
	return ecode;
}
コード例 #2
0
int
cmd_pfs_getid(const char *sel_path, const char *name, int privateid)
{
	hammer2_ioc_pfs_t pfs;
	int ecode = 0;
	int fd;
	uint32_t status;
	char *pfs_id_str = NULL;

	if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
		return(1);
	bzero(&pfs, sizeof(pfs));

	snprintf(pfs.name, sizeof(pfs.name), "%s", name);
	if (ioctl(fd, HAMMER2IOC_PFS_LOOKUP, &pfs) < 0) {
		perror("ioctl");
		ecode = 1;
	} else {
		if (privateid)
			uuid_to_string(&pfs.pfs_fsid, &pfs_id_str, &status);
		else
			uuid_to_string(&pfs.pfs_clid, &pfs_id_str, &status);
		printf("%s\n", pfs_id_str);
		free(pfs_id_str);
		pfs_id_str = NULL;
	}
	close(fd);
	return (ecode);
}
コード例 #3
0
int
cmd_remote_status(const char *sel_path, int all_opt __unused)
{
	hammer2_ioc_remote_t remote;
	int ecode = 0;
	int count = 0;
	int fd;

	if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
		return(1);
	bzero(&remote, sizeof(remote));

	while ((remote.copyid = remote.nextid) >= 0) {
		if (ioctl(fd, HAMMER2IOC_REMOTE_SCAN, &remote) < 0) {
			perror("ioctl");
			ecode = 1;
			break;
		}
		if (remote.copy1.copyid == 0)
			continue;
		if (count == 0)
			printf("CPYID LABEL           STATUS PATH\n");
		printf("%5d %-15s %c%c%c.%02x %s\n",
			remote.copy1.copyid,
			remote.copy1.label,
			'-', '-', '-',
			remote.copy1.priority,
			remote.copy1.path);
		++count;
	}
	if (count == 0)
		printf("No linkages found\n");
	return (ecode);
}
コード例 #4
0
int
cmd_remote_disconnect(const char *sel_path, const char *url)
{
	hammer2_ioc_remote_t remote;
	int ecode = 0;
	int fd;

	if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
		return(1);
	bzero(&remote, sizeof(remote));
	remote.copyid = -1;
	remote.fd = -1;
	if (strlen(url) >= sizeof(remote.copy1.path)) {
		fprintf(stderr, "hammer2: disconnect: Path too long\n");
		close(fd);
		return(1);
	}
	snprintf(remote.copy1.path, sizeof(remote.copy1.path), "%s", url);
	if (ioctl(fd, HAMMER2IOC_REMOTE_DEL, &remote) < 0) {
		perror("ioctl");
		ecode = 1;
	}
	close(fd);
	return ecode;
}
コード例 #5
0
ファイル: cmd_pfs.c プロジェクト: wan721/DragonFlyBSD
int
cmd_pfs_create(const char *sel_path, const char *name,
	       uint8_t pfs_type, const char *uuid_str)
{
	hammer2_ioc_pfs_t pfs;
	int ecode = 0;
	int fd;
	uint32_t status;

	/*
	 * Default to MASTER if no uuid was specified.
	 * Default to SLAVE if a uuid was specified.
	 *
	 * When adding masters to a cluster, the new PFS must be added as
	 * a slave and then upgraded to ensure proper synchronization.
	 */
	if (pfs_type == HAMMER2_PFSTYPE_NONE) {
		if (uuid_str)
			pfs_type = HAMMER2_PFSTYPE_SLAVE;
		else
			pfs_type = HAMMER2_PFSTYPE_MASTER;
	}

	if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
		return(1);
	bzero(&pfs, sizeof(pfs));
	snprintf(pfs.name, sizeof(pfs.name), "%s", name);
	pfs.pfs_type = pfs_type;
	if (uuid_str) {
		uuid_from_string(uuid_str, &pfs.pfs_clid, &status);
	} else {
		uuid_create(&pfs.pfs_clid, &status);
	}
	if (status == uuid_s_ok)
		uuid_create(&pfs.pfs_fsid, &status);
	if (status == uuid_s_ok) {
		if (ioctl(fd, HAMMER2IOC_PFS_CREATE, &pfs) < 0) {
			if (errno == EEXIST) {
				fprintf(stderr,
					"NOTE: Typically the same name is "
					"used for cluster elements on "
					"different mounts,\n"
					"      but cluster elements on the "
					"same mount require unique names.\n"
					"pfs-create %s: already present\n",
					name);
			} else {
				perror("ioctl");
			}
			ecode = 1;
		}
	} else {
		fprintf(stderr, "hammer2: pfs_create: badly formed uuid\n");
		ecode = 1;
	}
	close(fd);
	return (ecode);
}
コード例 #6
0
ファイル: cmd_setcheck.c プロジェクト: wan721/DragonFlyBSD
static int
cmd_setcheck_core(uint8_t check_algo, const char *path_str, struct stat *st)
{
    hammer2_ioc_inode_t inode;
    int fd;
    int res;

    fd = hammer2_ioctl_handle(path_str);
    if (fd < 0) {
        res = 3;
        goto failed;
    }
    res = ioctl(fd, HAMMER2IOC_INODE_GET, &inode);
    if (res < 0) {
        fprintf(stderr,
                "%s: HAMMER2IOC_INODE_GET: error %s\n",
                path_str, strerror(errno));
        res = 3;
        goto failed;
    }
    printf("%s\tcheck_algo=0x%02x\n", path_str, check_algo);
    inode.flags |= HAMMER2IOC_INODE_FLAG_CHECK;
    inode.ip_data.meta.check_algo = check_algo;
    res = ioctl(fd, HAMMER2IOC_INODE_SET, &inode);
    if (res < 0) {
        fprintf(stderr,
                "%s: HAMMER2IOC_INODE_SET: error %s\n",
                path_str, strerror(errno));
        res = 3;
        goto failed;
    }
    res = 0;

    if (RecurseOpt && S_ISDIR(st->st_mode)) {
        DIR *dir;
        char *path;
        struct dirent *den;

        if ((dir = fdopendir(fd)) != NULL) {
            while ((den = readdir(dir)) != NULL) {
                if (strcmp(den->d_name, ".") == 0 ||
                        strcmp(den->d_name, "..") == 0) {
                    continue;
                }
                asprintf(&path, "%s/%s", path_str, den->d_name);
                if (lstat(path, st) == 0)
                    cmd_setcheck_core(check_algo, path, st);
                free(path);
            }
            closedir(dir);
        }
    }
failed:
    close(fd);
    return res;
}
コード例 #7
0
ファイル: print_inode.c プロジェクト: mihaicarabas/dragonfly
void 
print_inode(char* inode_string)
{
	printf("Printing the inode's contents of directory/file %s\n", inode_string);
	int fd = hammer2_ioctl_handle(inode_string);
	if (fd != -1) {
		hammer2_ioc_inode_t inode;
		int res = ioctl(fd, HAMMER2IOC_INODE_GET, &inode);
		hammer2_inode_data_t inode_data;
		inode_data = inode.ip_data;
		printf("Got res = %d\n", res);
		printf("Printing inode data.\n");
		/*printf("version = %d\n", inode_data.version);
		printf("uflags = %d\n", inode_data.uflags);
		printf("rmajor = %d\n", inode_data.rmajor);
		printf("rminor = %d\n", inode_data.rminor);
		printf("ctime = %u !\n", (unsigned int)inode_data.ctime);
		printf("mtime = %u !\n", (unsigned int)inode_data.mtime);*/
		printf("type = %d\n", inode_data.type);
		printf("op_flags = %d\n", inode_data.op_flags);
		/*printf("cap_flags = %d\n", inode_data.cap_flags);
		printf("mode = %d\n", inode_data.mode);
		printf("inum = %u !\n", (unsigned int)inode_data.inum);
		printf("size = %u !\n", (unsigned int)inode_data.size),*/
		printf("name_key = %u !\n", (unsigned int)inode_data.name_key);
		/*printf("name_len = %d\n", inode_data.name_len);
		printf("ncopies = %d\n", inode_data.ncopies);*/
		printf("comp_algo = %d\n", inode_data.comp_algo);
		if (inode_data.op_flags != HAMMER2_OPFLAG_DIRECTDATA) {
			int i;
			for (i = 0; i < HAMMER2_SET_COUNT; ++i) {
				if (inode_data.u.blockset.blockref[i].type != HAMMER2_BREF_TYPE_EMPTY) {
					printf("blockrefs %d type = %d\n", i, inode_data.u.blockset.blockref[i].type);
					printf("blockrefs %d methods = %d\n", i, inode_data.u.blockset.blockref[i].methods);
					printf("blockrefs %d copyid = %d\n", i, inode_data.u.blockset.blockref[i].copyid);
					printf("blockrefs %d flags = %d\n", i, inode_data.u.blockset.blockref[i].flags);
					printf("blockrefs %d key = %u !\n", i, (unsigned int)inode_data.u.blockset.blockref[i].key);
				}
				else
					printf("blockrefs %d is empty.\n", i);
				}
			}
		else {
			printf("This inode has data instead of blockrefs.\n");
		}
	}
}
コード例 #8
0
int
cmd_pfs_delete(const char *sel_path, const char *name)
{
	hammer2_ioc_pfs_t pfs;
	int ecode = 0;
	int fd;

	if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
		return(1);
	bzero(&pfs, sizeof(pfs));
	snprintf(pfs.name, sizeof(pfs.name), "%s", name);

	if (ioctl(fd, HAMMER2IOC_PFS_DELETE, &pfs) < 0) {
		fprintf(stderr, "hammer2: pfs_delete(%s): %s\n",
			name, strerror(errno));
		ecode = 1;
	}
	close(fd);

	return (ecode);
}
コード例 #9
0
int
cmd_pfs_create(const char *sel_path, const char *name,
	       uint8_t pfs_type, const char *uuid_str)
{
	hammer2_ioc_pfs_t pfs;
	int ecode = 0;
	int fd;
	uint32_t status;

	/*
	 * Default to MASTER
	 */
	if (pfs_type == DMSG_PFSTYPE_NONE) {
		pfs_type = HAMMER2_PFSTYPE_MASTER;
	}

	if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
		return(1);
	bzero(&pfs, sizeof(pfs));
	snprintf(pfs.name, sizeof(pfs.name), "%s", name);
	pfs.pfs_type = pfs_type;
	if (uuid_str) {
		uuid_from_string(uuid_str, &pfs.pfs_clid, &status);
	} else {
		uuid_create(&pfs.pfs_clid, &status);
	}
	if (status == uuid_s_ok)
		uuid_create(&pfs.pfs_fsid, &status);
	if (status == uuid_s_ok) {
		if (ioctl(fd, HAMMER2IOC_PFS_CREATE, &pfs) < 0) {
			perror("ioctl");
			ecode = 1;
		}
	} else {
		fprintf(stderr, "hammer2: pfs_create: badly formed uuid\n");
		ecode = 1;
	}
	close(fd);
	return (ecode);
}
コード例 #10
0
int
cmd_pfs_list(const char *sel_path)
{
	hammer2_ioc_pfs_t pfs;
	int ecode = 0;
	int count = 0;
	int fd;
	uint32_t status;
	char *pfs_id_str = NULL;

	if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
		return(1);
	bzero(&pfs, sizeof(pfs));

	while ((pfs.name_key = pfs.name_next) != (hammer2_key_t)-1) {
		if (ioctl(fd, HAMMER2IOC_PFS_GET, &pfs) < 0) {
			perror("ioctl");
			ecode = 1;
			break;
		}
		if (count == 0) {
			printf("Type        "
			       "ClusterId (pfs_clid)                 "
			       "Label\n");
		}
		switch(pfs.pfs_type) {
		case DMSG_PFSTYPE_NONE:
			printf("NONE        ");
			break;
		case HAMMER2_PFSTYPE_CACHE:
			printf("CACHE       ");
			break;
		case HAMMER2_PFSTYPE_COPY:
			printf("COPY        ");
			break;
		case HAMMER2_PFSTYPE_SLAVE:
			printf("SLAVE       ");
			break;
		case HAMMER2_PFSTYPE_SOFT_SLAVE:
			printf("SOFT_SLAVE  ");
			break;
		case HAMMER2_PFSTYPE_SOFT_MASTER:
			printf("SOFT_MASTER ");
			break;
		case HAMMER2_PFSTYPE_MASTER:
			printf("MASTER      ");
			break;
		case HAMMER2_PFSTYPE_SNAPSHOT:
			printf("SNAPSHOT    ");
			break;
		default:
			printf("%02x          ", pfs.pfs_type);
			break;
		}
		uuid_to_string(&pfs.pfs_clid, &pfs_id_str, &status);
		printf("%s ", pfs_id_str);
		free(pfs_id_str);
		pfs_id_str = NULL;
		printf("%s\n", pfs.name);
		++count;
	}
	close(fd);

	return (ecode);
}