2 * Copyright (c) 2011-2012 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@dragonflybsd.org>
6 * by Venkatesh Srinivas <vsrinivas@dragonflybsd.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 cmd_pfs_list(const char *sel_path)
41 hammer2_ioc_pfs_t pfs;
46 char *pfs_id_str = NULL;
48 if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
50 bzero(&pfs, sizeof(pfs));
52 while ((pfs.name_key = pfs.name_next) != (hammer2_key_t)-1) {
53 if (ioctl(fd, HAMMER2IOC_PFS_GET, &pfs) < 0) {
63 switch(pfs.pfs_type) {
64 case HAMMER2_PFSTYPE_NONE:
67 case HAMMER2_PFSTYPE_ADMIN:
70 case HAMMER2_PFSTYPE_CACHE:
73 case HAMMER2_PFSTYPE_COPY:
76 case HAMMER2_PFSTYPE_SLAVE:
79 case HAMMER2_PFSTYPE_SOFT_SLAVE:
80 printf("SOFT_SLAVE ");
82 case HAMMER2_PFSTYPE_SOFT_MASTER:
83 printf("SOFT_MASTER ");
85 case HAMMER2_PFSTYPE_MASTER:
89 printf("%02x ", pfs.pfs_type);
92 uuid_to_string(&pfs.pfs_id, &pfs_id_str, &status);
93 printf("%s ", pfs_id_str);
96 printf("%s\n", pfs.name);
105 cmd_pfs_create(const char *sel_path, const char *name,
106 uint8_t pfs_type, const char *uuid_str)
108 hammer2_ioc_pfs_t pfs;
113 if (pfs_type == HAMMER2_PFSTYPE_NONE) {
114 fprintf(stderr, "hammer2: pfs_create: requires -t pfs_type\n");
118 if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
120 bzero(&pfs, sizeof(pfs));
121 snprintf(pfs.name, sizeof(pfs.name), "%s", name);
122 pfs.pfs_type = pfs_type;
124 uuid_from_string(uuid_str, &pfs.pfs_id, &status);
126 uuid_create(&pfs.pfs_id, &status);
128 if (status == uuid_s_ok)
129 uuid_create(&pfs.pfs_fsid, &status);
130 if (status == uuid_s_ok) {
131 if (ioctl(fd, HAMMER2IOC_PFS_CREATE, &pfs) < 0) {
136 fprintf(stderr, "hammer2: pfs_create: badly formed uuid\n");
144 cmd_pfs_delete(const char *sel_path, const char *name)
146 hammer2_ioc_pfs_t pfs;
150 if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
152 bzero(&pfs, sizeof(pfs));
153 snprintf(pfs.name, sizeof(pfs.name), "%s", name);
155 if (ioctl(fd, HAMMER2IOC_PFS_CREATE, &pfs) < 0) {
156 fprintf(stderr, "hammer2: pfs_delete(%s): %s\n",
157 name, strerror(errno));