Skip to content

Commit 03dd65f

Browse files
committed
v1.1.7
1 parent 773e7de commit 03dd65f

26 files changed

+1303
-115
lines changed

CHANGES

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
v1.1.7
2+
======
3+
- Add hammer2(8) pfs-create directive
4+
- Add hammer2(8) pfs-delete directive
5+
- Add hammer2(8) snapshot directive
6+
- Add hammer2(8) snapshot-debug directive
7+
- Reduce diff vs other BSD's
8+
19
v1.1.6
210
======
311
- Support MNT_UPDATE

README.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
OpenBSD [HAMMER2](https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/sys/vfs/hammer2/DESIGN)
22
========
33

4-
## About
5-
6-
+ HAMMER2 file system for OpenBSD
7-
84
## Requirements
95

106
+ OpenBSD 7.3
117

12-
+ OpenBSD 7.3 src tree under /usr/src
13-
14-
+ Bash
8+
+ src tree under /usr/src
159

1610
## OpenBSD build
1711

@@ -47,8 +41,4 @@ OpenBSD [HAMMER2](https://gitweb.dragonflybsd.org/dragonfly.git/blob/HEAD:/sys/v
4741

4842
## Notes
4943

50-
+ Tags are merely for packaging, nothing directly to do with file system version.
51-
52-
+ [makefs](https://github.com/kusumi/makefs) supports HAMMER2 image creation from a directory contents.
53-
54-
+ This repository will be abandoned once Linux or FreeBSD is stabilized with write support. OpenBSD is not the main target.
44+
+ This repository will be abandoned once Linux or FreeBSD is stabilized with write support. OpenBSD is not the main area of interest.

src/sbin/hammer2/Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
PROG= hammer2
44
SRCS= cmd_bulkfree.c cmd_cleanup.c cmd_debug.c cmd_destroy.c cmd_emergency.c \
5-
cmd_growfs.c cmd_pfs.c cmd_setcheck.c cmd_setcomp.c cmd_stat.c \
6-
cmd_volume.c main.c ondisk.c print_inode.c subs.c xxhash.c icrc32.c
5+
cmd_growfs.c cmd_pfs.c cmd_setcheck.c cmd_setcomp.c cmd_snapshot.c \
6+
cmd_stat.c cmd_volume.c main.c ondisk.c print_inode.c subs.c xxhash.c \
7+
icrc32.c
78
MAN= hammer2.8
89

910
.PATH: ../../sys/libkern ../../sys/fs/hammer2/xxhash

src/sbin/hammer2/cmd_pfs.c

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,137 @@ cmd_pfs_getid(const char *sel_path, const char *name, int privateid)
150150
close(fd);
151151
return (ecode);
152152
}
153+
154+
int
155+
cmd_pfs_create(const char *sel_path, const char *name,
156+
uint8_t pfs_type, const char *uuid_str)
157+
{
158+
hammer2_ioc_pfs_t pfs;
159+
int ecode = 0;
160+
int fd;
161+
uint32_t status;
162+
163+
/*
164+
* Default to MASTER if no uuid was specified.
165+
* Default to SLAVE if a uuid was specified.
166+
*
167+
* When adding masters to a cluster, the new PFS must be added as
168+
* a slave and then upgraded to ensure proper synchronization.
169+
*/
170+
if (pfs_type == HAMMER2_PFSTYPE_NONE) {
171+
if (uuid_str)
172+
pfs_type = HAMMER2_PFSTYPE_SLAVE;
173+
else
174+
pfs_type = HAMMER2_PFSTYPE_MASTER;
175+
}
176+
177+
if ((fd = hammer2_ioctl_handle(sel_path)) < 0)
178+
return(1);
179+
bzero(&pfs, sizeof(pfs));
180+
snprintf(pfs.name, sizeof(pfs.name), "%s", name);
181+
pfs.pfs_type = pfs_type;
182+
if (uuid_str) {
183+
uuid_from_string(uuid_str, &pfs.pfs_clid, &status);
184+
} else {
185+
uuid_create(&pfs.pfs_clid, &status);
186+
}
187+
if (status == uuid_s_ok)
188+
uuid_create(&pfs.pfs_fsid, &status);
189+
if (status == uuid_s_ok) {
190+
if (ioctl(fd, HAMMER2IOC_PFS_CREATE, &pfs) < 0) {
191+
if (errno == EEXIST) {
192+
fprintf(stderr,
193+
"NOTE: Typically the same name is "
194+
"used for cluster elements on "
195+
"different mounts,\n"
196+
" but cluster elements on the "
197+
"same mount require unique names.\n"
198+
"hammer2: pfs_create(%s): already present\n",
199+
name);
200+
} else {
201+
fprintf(stderr, "hammer2: pfs_create(%s): %s\n",
202+
name, strerror(errno));
203+
}
204+
ecode = 1;
205+
} else {
206+
printf("hammer2: pfs_create(%s): SUCCESS\n", name);
207+
}
208+
} else {
209+
fprintf(stderr, "hammer2: pfs_create(%s): badly formed uuid\n",
210+
name);
211+
ecode = 1;
212+
}
213+
close(fd);
214+
return (ecode);
215+
}
216+
217+
int
218+
cmd_pfs_delete(const char *sel_path, char **av, int ac)
219+
{
220+
hammer2_ioc_pfs_t pfs;
221+
int ecode = 0;
222+
int fd;
223+
int i;
224+
int n;
225+
int use_fd;
226+
int nmnts = 0;
227+
char **mnts = NULL;
228+
229+
if (sel_path == NULL)
230+
mnts = get_hammer2_mounts(&nmnts);
231+
232+
for (i = 1; i < ac; ++i) {
233+
int enoents = 0;
234+
bzero(&pfs, sizeof(pfs));
235+
snprintf(pfs.name, sizeof(pfs.name), "%s", av[i]);
236+
237+
if (sel_path) {
238+
use_fd = hammer2_ioctl_handle(sel_path);
239+
} else {
240+
use_fd = -1;
241+
for (n = 0; n < nmnts; ++n) {
242+
if ((fd = hammer2_ioctl_handle(mnts[n])) < 0) {
243+
enoents++;
244+
continue;
245+
}
246+
if (ioctl(fd, HAMMER2IOC_PFS_LOOKUP, &pfs) < 0) {
247+
enoents++;
248+
continue;
249+
}
250+
if (use_fd >= 0) {
251+
fprintf(stderr,
252+
"hammer2: pfs_delete(%s): "
253+
"Duplicate PFS name, "
254+
"must specify mount\n",
255+
av[i]);
256+
close(use_fd);
257+
use_fd = -1;
258+
break;
259+
}
260+
use_fd = fd;
261+
}
262+
}
263+
if (use_fd >= 0) {
264+
if (ioctl(use_fd, HAMMER2IOC_PFS_DELETE, &pfs) < 0) {
265+
printf("hammer2: pfs_delete(%s): %s\n",
266+
av[i], strerror(errno));
267+
ecode = 1;
268+
} else {
269+
printf("hammer2: pfs_delete(%s): SUCCESS\n",
270+
av[i]);
271+
}
272+
close(use_fd);
273+
} else {
274+
if (enoents == nmnts)
275+
printf("hammer2: pfs_delete(%s): %s not found\n",
276+
av[i], av[i]);
277+
else
278+
printf("hammer2: pfs_delete(%s): FAILED\n",
279+
av[i]);
280+
ecode = 1;
281+
}
282+
}
283+
if (mnts)
284+
put_hammer2_mounts(nmnts, mnts);
285+
return (ecode);
286+
}

src/sbin/hammer2/cmd_setcheck.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ cmd_setcheck(const char *check_str, char **paths)
5151

5252
ecode = 0;
5353

54-
if (isdigit(check_str[0])) {
54+
if (isdigit((int)check_str[0])) {
5555
check_algo = strtol(check_str, NULL, 0);
5656
} else {
5757
check_algo = HAMMER2_CHECK_STRINGS_COUNT;

src/sbin/hammer2/cmd_setcomp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ cmd_setcomp(const char *comp_str, char **paths)
5858
s2 = s1 ? strtok(NULL, ":") : NULL;
5959
ecode = 0;
6060

61-
if (isdigit(s1[0])) {
61+
if (isdigit((int)s1[0])) {
6262
comp_algo = strtol(s1, NULL, 0);
6363
} else {
6464
comp_algo = HAMMER2_COMP_STRINGS_COUNT;
@@ -81,7 +81,7 @@ cmd_setcomp(const char *comp_str, char **paths)
8181
}
8282
if (s2 == NULL) {
8383
comp_level = 0;
84-
} else if (isdigit(s2[0])) {
84+
} else if (isdigit((int)s2[0])) {
8585
comp_level = strtol(s2, NULL, 0);
8686
} else if (strcasecmp(s2, "default") == 0) {
8787
comp_level = 0;

src/sbin/hammer2/cmd_snapshot.c

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* SPDX-License-Identifier: BSD-3-Clause
3+
*
4+
* Copyright (c) 2022-2023 Tomohiro Kusumi <tkusumi@netbsd.org>
5+
* Copyright (c) 2011-2013 The DragonFly Project. All rights reserved.
6+
*
7+
* This code is derived from software contributed to The DragonFly Project
8+
* by Matthew Dillon <dillon@dragonflybsd.org>
9+
* by Venkatesh Srinivas <vsrinivas@dragonflybsd.org>
10+
*
11+
* Redistribution and use in source and binary forms, with or without
12+
* modification, are permitted provided that the following conditions
13+
* are met:
14+
*
15+
* 1. Redistributions of source code must retain the above copyright
16+
* notice, this list of conditions and the following disclaimer.
17+
* 2. Redistributions in binary form must reproduce the above copyright
18+
* notice, this list of conditions and the following disclaimer in
19+
* the documentation and/or other materials provided with the
20+
* distribution.
21+
* 3. Neither the name of The DragonFly Project nor the names of its
22+
* contributors may be used to endorse or promote products derived
23+
* from this software without specific, prior written permission.
24+
*
25+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26+
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29+
* COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30+
* INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
31+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
33+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
34+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
35+
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36+
* SUCH DAMAGE.
37+
*/
38+
39+
#include "hammer2.h"
40+
41+
/*
42+
* The snapshot is named <PFSNAME>_<YYYYMMDD.HHMMSS.TRANSID> unless
43+
* overridden by a label.
44+
*
45+
* When local non-cache media is involved the media is
46+
* first synchronized and the snapshot is then based on
47+
* the media.
48+
*
49+
* If the media is remote the snapshot is created on the remote
50+
* end (if you have sufficient administrative rights) and a local
51+
* ADMIN or CACHE PFS is created with a connection to the snapshot
52+
* on the remote.
53+
*
54+
* If the client has snapshot rights to multiple remotes then TBD.
55+
*/
56+
57+
int
58+
cmd_pfs_snapshot(const char *sel_path, const char *path, const char *label,
59+
uint32_t pfs_flags)
60+
{
61+
hammer2_ioc_pfs_t pfs;
62+
int ecode = 0;
63+
int fd;
64+
char filename[NAME_MAX + 256];
65+
time_t t;
66+
struct tm *tp;
67+
68+
if (path == NULL) {
69+
fd = hammer2_ioctl_handle(sel_path);
70+
} else {
71+
fd = open(path, O_RDONLY);
72+
if (fd < 0)
73+
fprintf(stderr, "Unable to open %s\n", path);
74+
}
75+
if (fd < 0)
76+
return 1;
77+
78+
if (label == NULL) {
79+
time(&t);
80+
tp = localtime(&t);
81+
bzero(&pfs, sizeof(pfs));
82+
pfs.name_key = (hammer2_key_t)-1;
83+
if (ioctl(fd, HAMMER2IOC_PFS_GET, &pfs) < 0) {
84+
perror("ioctl");
85+
}
86+
snprintf(filename, sizeof(filename),
87+
"%s.%04d%02d%02d.%02d%02d%02d",
88+
pfs.name,
89+
tp->tm_year + 1900,
90+
tp->tm_mon + 1,
91+
tp->tm_mday,
92+
tp->tm_hour,
93+
tp->tm_min,
94+
tp->tm_sec);
95+
label = filename;
96+
}
97+
98+
bzero(&pfs, sizeof(pfs));
99+
strlcpy(pfs.name, label, sizeof(pfs.name));
100+
pfs.pfs_flags = pfs_flags;
101+
102+
if (ioctl(fd, HAMMER2IOC_PFS_SNAPSHOT, &pfs) < 0) {
103+
perror("ioctl");
104+
ecode = 1;
105+
} else {
106+
printf("created snapshot %s\n", label);
107+
}
108+
return ecode;
109+
}

0 commit comments

Comments
 (0)