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) {
60 "ClusterId (pfs_clid) "
63 switch(pfs.pfs_type) {
64 case HAMMER2_PFSTYPE_NONE:
67 case HAMMER2_PFSTYPE_CACHE:
70 case HAMMER2_PFSTYPE_COPY:
73 case HAMMER2_PFSTYPE_SLAVE:
76 case HAMMER2_PFSTYPE_SOFT_SLAVE:
77 printf("SOFT_SLAVE ");
79 case HAMMER2_PFSTYPE_SOFT_MASTER:
80 printf("SOFT_MASTER ");
82 case HAMMER2_PFSTYPE_MASTER:
83 switch (pfs.pfs_subtype) {
84 case HAMMER2_PFSSUBTYPE_NONE:
87 case HAMMER2_PFSSUBTYPE_SNAPSHOT:
91 printf("MASTER(sub?)");
95 printf("%02x ", pfs.pfs_type);
98 uuid_to_string(&pfs.pfs_clid, &pfs_id_str, &status);
99 printf("%s ", pfs_id_str);
102 printf("%s\n", pfs.name);
111 cmd_pfs_getid(const char *sel_path, const char *name, int privateid)
113 hammer2_ioc_pfs_t pfs;
117 char *pfs_id_str = NULL;
119 if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
121 bzero(&pfs, sizeof(pfs));
123 snprintf(pfs.name, sizeof(pfs.name), "%s", name);
124 if (ioctl(fd, HAMMER2IOC_PFS_LOOKUP, &pfs) < 0) {
129 uuid_to_string(&pfs.pfs_fsid, &pfs_id_str, &status);
131 uuid_to_string(&pfs.pfs_clid, &pfs_id_str, &status);
132 printf("%s\n", pfs_id_str);
142 cmd_pfs_create(const char *sel_path, const char *name,
143 uint8_t pfs_type, const char *uuid_str)
145 hammer2_ioc_pfs_t pfs;
151 * Default to MASTER if no uuid was specified.
152 * Default to SLAVE if a uuid was specified.
154 * When adding masters to a cluster, the new PFS must be added as
155 * a slave and then upgraded to ensure proper synchronization.
157 if (pfs_type == HAMMER2_PFSTYPE_NONE) {
159 pfs_type = HAMMER2_PFSTYPE_SLAVE;
161 pfs_type = HAMMER2_PFSTYPE_MASTER;
164 if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
166 bzero(&pfs, sizeof(pfs));
167 snprintf(pfs.name, sizeof(pfs.name), "%s", name);
168 pfs.pfs_type = pfs_type;
170 uuid_from_string(uuid_str, &pfs.pfs_clid, &status);
172 uuid_create(&pfs.pfs_clid, &status);
174 if (status == uuid_s_ok)
175 uuid_create(&pfs.pfs_fsid, &status);
176 if (status == uuid_s_ok) {
177 if (ioctl(fd, HAMMER2IOC_PFS_CREATE, &pfs) < 0) {
178 if (errno == EEXIST) {
180 "NOTE: Typically the same name is "
181 "used for cluster elements on "
182 "different mounts,\n"
183 " but cluster elements on the "
184 "same mount require unique names.\n"
185 "pfs-create %s: already present\n",
193 fprintf(stderr, "hammer2: pfs_create: badly formed uuid\n");
201 cmd_pfs_delete(const char *sel_path, const char *name)
203 hammer2_ioc_pfs_t pfs;
207 if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
209 bzero(&pfs, sizeof(pfs));
210 snprintf(pfs.name, sizeof(pfs.name), "%s", name);
212 if (ioctl(fd, HAMMER2IOC_PFS_DELETE, &pfs) < 0) {
213 fprintf(stderr, "hammer2: pfs_delete(%s): %s\n",
214 name, strerror(errno));