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_SLAVE:
73 case HAMMER2_PFSTYPE_SOFT_SLAVE:
74 printf("SOFT_SLAVE ");
76 case HAMMER2_PFSTYPE_SOFT_MASTER:
77 printf("SOFT_MASTER ");
79 case HAMMER2_PFSTYPE_MASTER:
80 switch (pfs.pfs_subtype) {
81 case HAMMER2_PFSSUBTYPE_NONE:
84 case HAMMER2_PFSSUBTYPE_SNAPSHOT:
87 case HAMMER2_PFSSUBTYPE_AUTOSNAP:
91 printf("MASTER(sub?)");
96 printf("%02x ", pfs.pfs_type);
99 uuid_to_string(&pfs.pfs_clid, &pfs_id_str, &status);
100 printf("%s ", pfs_id_str);
103 printf("%s\n", pfs.name);
112 cmd_pfs_getid(const char *sel_path, const char *name, int privateid)
114 hammer2_ioc_pfs_t pfs;
118 char *pfs_id_str = NULL;
120 if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
122 bzero(&pfs, sizeof(pfs));
124 snprintf(pfs.name, sizeof(pfs.name), "%s", name);
125 if (ioctl(fd, HAMMER2IOC_PFS_LOOKUP, &pfs) < 0) {
130 uuid_to_string(&pfs.pfs_fsid, &pfs_id_str, &status);
132 uuid_to_string(&pfs.pfs_clid, &pfs_id_str, &status);
133 printf("%s\n", pfs_id_str);
143 cmd_pfs_create(const char *sel_path, const char *name,
144 uint8_t pfs_type, const char *uuid_str)
146 hammer2_ioc_pfs_t pfs;
152 * Default to MASTER if no uuid was specified.
153 * Default to SLAVE if a uuid was specified.
155 * When adding masters to a cluster, the new PFS must be added as
156 * a slave and then upgraded to ensure proper synchronization.
158 if (pfs_type == HAMMER2_PFSTYPE_NONE) {
160 pfs_type = HAMMER2_PFSTYPE_SLAVE;
162 pfs_type = HAMMER2_PFSTYPE_MASTER;
165 if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
167 bzero(&pfs, sizeof(pfs));
168 snprintf(pfs.name, sizeof(pfs.name), "%s", name);
169 pfs.pfs_type = pfs_type;
171 uuid_from_string(uuid_str, &pfs.pfs_clid, &status);
173 uuid_create(&pfs.pfs_clid, &status);
175 if (status == uuid_s_ok)
176 uuid_create(&pfs.pfs_fsid, &status);
177 if (status == uuid_s_ok) {
178 if (ioctl(fd, HAMMER2IOC_PFS_CREATE, &pfs) < 0) {
179 if (errno == EEXIST) {
181 "NOTE: Typically the same name is "
182 "used for cluster elements on "
183 "different mounts,\n"
184 " but cluster elements on the "
185 "same mount require unique names.\n"
186 "pfs-create %s: already present\n",
194 fprintf(stderr, "hammer2: pfs_create: badly formed uuid\n");
202 cmd_pfs_delete(const char *sel_path, const char *name)
204 hammer2_ioc_pfs_t pfs;
208 if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
210 bzero(&pfs, sizeof(pfs));
211 snprintf(pfs.name, sizeof(pfs.name), "%s", name);
213 if (ioctl(fd, HAMMER2IOC_PFS_DELETE, &pfs) < 0) {
214 fprintf(stderr, "hammer2: pfs_delete(%s): %s\n",
215 name, strerror(errno));