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
:
85 case HAMMER2_PFSTYPE_SNAPSHOT
:
89 printf("%02x ", pfs
.pfs_type
);
92 uuid_to_string(&pfs
.pfs_clid
, &pfs_id_str
, &status
);
93 printf("%s ", pfs_id_str
);
96 printf("%s\n", pfs
.name
);
105 cmd_pfs_getid(const char *sel_path
, const char *name
, int privateid
)
107 hammer2_ioc_pfs_t pfs
;
111 char *pfs_id_str
= NULL
;
113 if ((fd
= hammer2_ioctl_handle(sel_path
)) < 0)
115 bzero(&pfs
, sizeof(pfs
));
117 snprintf(pfs
.name
, sizeof(pfs
.name
), "%s", name
);
118 if (ioctl(fd
, HAMMER2IOC_PFS_LOOKUP
, &pfs
) < 0) {
123 uuid_to_string(&pfs
.pfs_fsid
, &pfs_id_str
, &status
);
125 uuid_to_string(&pfs
.pfs_clid
, &pfs_id_str
, &status
);
126 printf("%s\n", pfs_id_str
);
136 cmd_pfs_create(const char *sel_path
, const char *name
,
137 uint8_t pfs_type
, const char *uuid_str
)
139 hammer2_ioc_pfs_t pfs
;
147 if (pfs_type
== HAMMER2_PFSTYPE_NONE
) {
148 pfs_type
= HAMMER2_PFSTYPE_MASTER
;
151 if ((fd
= hammer2_ioctl_handle(sel_path
)) < 0)
153 bzero(&pfs
, sizeof(pfs
));
154 snprintf(pfs
.name
, sizeof(pfs
.name
), "%s", name
);
155 pfs
.pfs_type
= pfs_type
;
157 uuid_from_string(uuid_str
, &pfs
.pfs_clid
, &status
);
159 uuid_create(&pfs
.pfs_clid
, &status
);
161 if (status
== uuid_s_ok
)
162 uuid_create(&pfs
.pfs_fsid
, &status
);
163 if (status
== uuid_s_ok
) {
164 if (ioctl(fd
, HAMMER2IOC_PFS_CREATE
, &pfs
) < 0) {
169 fprintf(stderr
, "hammer2: pfs_create: badly formed uuid\n");
177 cmd_pfs_delete(const char *sel_path
, const char *name
)
179 hammer2_ioc_pfs_t pfs
;
183 if ((fd
= hammer2_ioctl_handle(sel_path
)) < 0)
185 bzero(&pfs
, sizeof(pfs
));
186 snprintf(pfs
.name
, sizeof(pfs
.name
), "%s", name
);
188 if (ioctl(fd
, HAMMER2IOC_PFS_DELETE
, &pfs
) < 0) {
189 fprintf(stderr
, "hammer2: pfs_delete(%s): %s\n",
190 name
, strerror(errno
));