hammer2 - Add debug ioctl
[dragonfly.git] / sys / vfs / hammer2 / hammer2_ioctl.c
CommitLineData
2910a90c 1/*
8138a154 2 * Copyright (c) 2011-2014 The DragonFly Project. All rights reserved.
2910a90c
MD
3 *
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>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
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
17 * distribution.
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.
21 *
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
33 * SUCH DAMAGE.
34 */
35/*
36 * Ioctl Functions.
37 *
38 * WARNING! The ioctl functions which manipulate the connection state need
39 * to be able to run without deadlock on the volume's chain lock.
40 * Most of these functions use a separate lock.
41 */
42
43#include "hammer2.h"
44
ae183399 45static int hammer2_ioctl_version_get(hammer2_inode_t *ip, void *data);
1a34728c
MD
46static int hammer2_ioctl_recluster(hammer2_inode_t *ip, void *data);
47static int hammer2_ioctl_remote_scan(hammer2_inode_t *ip, void *data);
ae183399
MD
48static int hammer2_ioctl_remote_add(hammer2_inode_t *ip, void *data);
49static int hammer2_ioctl_remote_del(hammer2_inode_t *ip, void *data);
50static int hammer2_ioctl_remote_rep(hammer2_inode_t *ip, void *data);
51static int hammer2_ioctl_socket_get(hammer2_inode_t *ip, void *data);
52static int hammer2_ioctl_socket_set(hammer2_inode_t *ip, void *data);
53static int hammer2_ioctl_pfs_get(hammer2_inode_t *ip, void *data);
458ecb1b 54static int hammer2_ioctl_pfs_lookup(hammer2_inode_t *ip, void *data);
ae183399 55static int hammer2_ioctl_pfs_create(hammer2_inode_t *ip, void *data);
a864c5d9 56static int hammer2_ioctl_pfs_snapshot(hammer2_inode_t *ip, void *data);
ae183399 57static int hammer2_ioctl_pfs_delete(hammer2_inode_t *ip, void *data);
344d4f82
MD
58static int hammer2_ioctl_inode_get(hammer2_inode_t *ip, void *data);
59static int hammer2_ioctl_inode_set(hammer2_inode_t *ip, void *data);
355d67fc
MD
60//static int hammer2_ioctl_inode_comp_set(hammer2_inode_t *ip, void *data);
61//static int hammer2_ioctl_inode_comp_rec_set(hammer2_inode_t *ip, void *data);
62//static int hammer2_ioctl_inode_comp_rec_set2(hammer2_inode_t *ip, void *data);
2910a90c
MD
63
64int
65hammer2_ioctl(hammer2_inode_t *ip, u_long com, void *data, int fflag,
66 struct ucred *cred)
67{
68 int error;
69
70 /*
71 * Standard root cred checks, will be selectively ignored below
72 * for ioctls that do not require root creds.
73 */
74 error = priv_check_cred(cred, PRIV_HAMMER_IOCTL, 0);
75
76 switch(com) {
ae183399
MD
77 case HAMMER2IOC_VERSION_GET:
78 error = hammer2_ioctl_version_get(ip, data);
2910a90c 79 break;
1a34728c 80 case HAMMER2IOC_RECLUSTER:
2910a90c 81 if (error == 0)
1a34728c
MD
82 error = hammer2_ioctl_recluster(ip, data);
83 break;
84 case HAMMER2IOC_REMOTE_SCAN:
85 if (error == 0)
86 error = hammer2_ioctl_remote_scan(ip, data);
2910a90c 87 break;
ae183399 88 case HAMMER2IOC_REMOTE_ADD:
2910a90c 89 if (error == 0)
ae183399 90 error = hammer2_ioctl_remote_add(ip, data);
2910a90c 91 break;
ae183399 92 case HAMMER2IOC_REMOTE_DEL:
2910a90c 93 if (error == 0)
ae183399 94 error = hammer2_ioctl_remote_del(ip, data);
2910a90c 95 break;
ae183399 96 case HAMMER2IOC_REMOTE_REP:
2910a90c 97 if (error == 0)
ae183399 98 error = hammer2_ioctl_remote_rep(ip, data);
2910a90c 99 break;
ae183399 100 case HAMMER2IOC_SOCKET_GET:
2910a90c 101 if (error == 0)
ae183399 102 error = hammer2_ioctl_socket_get(ip, data);
2910a90c 103 break;
ae183399
MD
104 case HAMMER2IOC_SOCKET_SET:
105 if (error == 0)
106 error = hammer2_ioctl_socket_set(ip, data);
107 break;
108 case HAMMER2IOC_PFS_GET:
2910a90c 109 if (error == 0)
ae183399
MD
110 error = hammer2_ioctl_pfs_get(ip, data);
111 break;
458ecb1b
MD
112 case HAMMER2IOC_PFS_LOOKUP:
113 if (error == 0)
114 error = hammer2_ioctl_pfs_lookup(ip, data);
115 break;
ae183399
MD
116 case HAMMER2IOC_PFS_CREATE:
117 if (error == 0)
118 error = hammer2_ioctl_pfs_create(ip, data);
119 break;
120 case HAMMER2IOC_PFS_DELETE:
121 if (error == 0)
122 error = hammer2_ioctl_pfs_delete(ip, data);
2910a90c 123 break;
a864c5d9
MD
124 case HAMMER2IOC_PFS_SNAPSHOT:
125 if (error == 0)
126 error = hammer2_ioctl_pfs_snapshot(ip, data);
127 break;
344d4f82
MD
128 case HAMMER2IOC_INODE_GET:
129 error = hammer2_ioctl_inode_get(ip, data);
130 break;
131 case HAMMER2IOC_INODE_SET:
132 if (error == 0)
133 error = hammer2_ioctl_inode_set(ip, data);
134 break;
355d67fc
MD
135 /*case HAMMER2IOC_INODE_COMP_SET:
136 error = hammer2_ioctl_inode_comp_set(ip, data);
137 break;
138 case HAMMER2IOC_INODE_COMP_REC_SET:
139 error = hammer2_ioctl_inode_comp_rec_set(ip, data);
140 break;
141 case HAMMER2IOC_INODE_COMP_REC_SET2:
142 error = hammer2_ioctl_inode_comp_rec_set2(ip, data);
143 break;*/
2910a90c
MD
144 default:
145 error = EOPNOTSUPP;
146 break;
147 }
148 return (error);
149}
150
151/*
152 * Retrieve version and basic info
153 */
154static int
ae183399 155hammer2_ioctl_version_get(hammer2_inode_t *ip, void *data)
2910a90c 156{
58e43599 157 hammer2_mount_t *hmp = ip->pmp->iroot->cluster.focus->hmp;
2910a90c
MD
158 hammer2_ioc_version_t *version = data;
159
160 version->version = hmp->voldata.version;
161 return 0;
162}
163
1a34728c
MD
164static int
165hammer2_ioctl_recluster(hammer2_inode_t *ip, void *data)
166{
167 hammer2_ioc_recluster_t *recl = data;
168 struct file *fp;
169
170 fp = holdfp(curproc->p_fd, recl->fd, -1);
171 if (fp) {
172 kprintf("reconnect to cluster\n");
173 hammer2_cluster_reconnect(ip->pmp, fp);
174 return 0;
175 } else {
176 return EINVAL;
177 }
178}
179
2910a90c
MD
180/*
181 * Retrieve information about a remote
182 */
183static int
1a34728c 184hammer2_ioctl_remote_scan(hammer2_inode_t *ip, void *data)
2910a90c 185{
58e43599 186 hammer2_mount_t *hmp = ip->pmp->iroot->cluster.focus->hmp;
2910a90c
MD
187 hammer2_ioc_remote_t *remote = data;
188 int copyid = remote->copyid;
189
190 if (copyid < 0 || copyid >= HAMMER2_COPYID_COUNT)
191 return (EINVAL);
192
193 hammer2_voldata_lock(hmp);
194 remote->copy1 = hmp->voldata.copyinfo[copyid];
50456506 195 hammer2_voldata_unlock(hmp);
2910a90c
MD
196
197 /*
198 * Adjust nextid (GET only)
199 */
200 while (++copyid < HAMMER2_COPYID_COUNT &&
201 hmp->voldata.copyinfo[copyid].copyid == 0) {
1a34728c 202 ;
2910a90c
MD
203 }
204 if (copyid == HAMMER2_COPYID_COUNT)
205 remote->nextid = -1;
206 else
207 remote->nextid = copyid;
208
209 return(0);
210}
211
212/*
213 * Add new remote entry
214 */
215static int
ae183399 216hammer2_ioctl_remote_add(hammer2_inode_t *ip, void *data)
2910a90c 217{
2910a90c 218 hammer2_ioc_remote_t *remote = data;
a5913bdf
MD
219 hammer2_pfsmount_t *pmp = ip->pmp;
220 hammer2_mount_t *hmp;
2910a90c
MD
221 int copyid = remote->copyid;
222 int error = 0;
223
224 if (copyid >= HAMMER2_COPYID_COUNT)
225 return (EINVAL);
226
58e43599 227 hmp = pmp->iroot->cluster.focus->hmp; /* XXX */
2910a90c
MD
228 hammer2_voldata_lock(hmp);
229 if (copyid < 0) {
230 for (copyid = 1; copyid < HAMMER2_COPYID_COUNT; ++copyid) {
231 if (hmp->voldata.copyinfo[copyid].copyid == 0)
232 break;
233 }
234 if (copyid == HAMMER2_COPYID_COUNT) {
235 error = ENOSPC;
236 goto failed;
237 }
238 }
50456506 239 hammer2_voldata_modify(hmp);
2910a90c
MD
240 remote->copy1.copyid = copyid;
241 hmp->voldata.copyinfo[copyid] = remote->copy1;
1a34728c 242 hammer2_volconf_update(pmp, copyid);
2910a90c 243failed:
50456506 244 hammer2_voldata_unlock(hmp);
2910a90c
MD
245 return (error);
246}
247
248/*
249 * Delete existing remote entry
250 */
251static int
ae183399 252hammer2_ioctl_remote_del(hammer2_inode_t *ip, void *data)
2910a90c 253{
2910a90c 254 hammer2_ioc_remote_t *remote = data;
a5913bdf
MD
255 hammer2_pfsmount_t *pmp = ip->pmp;
256 hammer2_mount_t *hmp;
2910a90c
MD
257 int copyid = remote->copyid;
258 int error = 0;
259
58e43599 260 hmp = pmp->iroot->cluster.focus->hmp; /* XXX */
2910a90c
MD
261 if (copyid >= HAMMER2_COPYID_COUNT)
262 return (EINVAL);
263 remote->copy1.path[sizeof(remote->copy1.path) - 1] = 0;
264 hammer2_voldata_lock(hmp);
265 if (copyid < 0) {
266 for (copyid = 1; copyid < HAMMER2_COPYID_COUNT; ++copyid) {
267 if (hmp->voldata.copyinfo[copyid].copyid == 0)
268 continue;
269 if (strcmp(remote->copy1.path,
270 hmp->voldata.copyinfo[copyid].path) == 0) {
271 break;
272 }
273 }
274 if (copyid == HAMMER2_COPYID_COUNT) {
275 error = ENOENT;
276 goto failed;
277 }
278 }
50456506 279 hammer2_voldata_modify(hmp);
2910a90c 280 hmp->voldata.copyinfo[copyid].copyid = 0;
1a34728c 281 hammer2_volconf_update(pmp, copyid);
2910a90c 282failed:
50456506 283 hammer2_voldata_unlock(hmp);
2910a90c
MD
284 return (error);
285}
286
287/*
288 * Replace existing remote entry
289 */
290static int
ae183399 291hammer2_ioctl_remote_rep(hammer2_inode_t *ip, void *data)
2910a90c 292{
2910a90c 293 hammer2_ioc_remote_t *remote = data;
a5913bdf 294 hammer2_mount_t *hmp;
2910a90c
MD
295 int copyid = remote->copyid;
296
58e43599 297 hmp = ip->pmp->iroot->cluster.focus->hmp; /* XXX */
a5913bdf 298
2910a90c
MD
299 if (copyid < 0 || copyid >= HAMMER2_COPYID_COUNT)
300 return (EINVAL);
301
302 hammer2_voldata_lock(hmp);
50456506 303 hammer2_voldata_modify(hmp);
1a34728c 304 /*hammer2_volconf_update(pmp, copyid);*/
50456506 305 hammer2_voldata_unlock(hmp);
2910a90c
MD
306
307 return(0);
308}
309
310/*
311 * Retrieve communications socket
312 */
313static int
ae183399 314hammer2_ioctl_socket_get(hammer2_inode_t *ip, void *data)
2910a90c
MD
315{
316 return (EOPNOTSUPP);
317}
318
319/*
320 * Set communications socket for connection
321 */
322static int
ae183399 323hammer2_ioctl_socket_set(hammer2_inode_t *ip, void *data)
2910a90c 324{
2910a90c 325 hammer2_ioc_remote_t *remote = data;
a5913bdf 326 hammer2_mount_t *hmp;
2910a90c
MD
327 int copyid = remote->copyid;
328
58e43599 329 hmp = ip->pmp->iroot->cluster.focus->hmp; /* XXX */
2910a90c
MD
330 if (copyid < 0 || copyid >= HAMMER2_COPYID_COUNT)
331 return (EINVAL);
332
333 hammer2_voldata_lock(hmp);
50456506 334 hammer2_voldata_unlock(hmp);
2910a90c
MD
335
336 return(0);
337}
ae183399
MD
338
339/*
a864c5d9
MD
340 * Used to scan and retrieve PFS information. PFS's are directories under
341 * the super-root.
342 *
343 * To scan PFSs pass name_key=0. The function will scan for the next
344 * PFS and set all fields, as well as set name_next to the next key.
345 * When no PFSs remain, name_next is set to (hammer2_key_t)-1.
346 *
347 * To retrieve the PFS associated with the file descriptor, pass
348 * name_key set to (hammer2_key_t)-1.
ae183399
MD
349 */
350static int
351hammer2_ioctl_pfs_get(hammer2_inode_t *ip, void *data)
352{
6a5f4fe6 353 const hammer2_inode_data_t *ipdata;
476d2aad
MD
354 hammer2_mount_t *hmp;
355 hammer2_ioc_pfs_t *pfs;
278ab2b2
MD
356 hammer2_cluster_t *cparent;
357 hammer2_cluster_t *rcluster;
358 hammer2_cluster_t *cluster;
1897c66e 359 hammer2_key_t key_next;
476d2aad 360 int error;
278ab2b2 361 int ddflag;
ae183399 362
476d2aad 363 error = 0;
58e43599 364 hmp = ip->pmp->iroot->cluster.focus->hmp; /* XXX */
476d2aad 365 pfs = data;
50456506 366 cparent = hammer2_inode_lock_ex(hmp->spmp->iroot);
278ab2b2 367 rcluster = hammer2_inode_lock_ex(ip->pmp->iroot);
ae183399
MD
368
369 /*
370 * Search for the first key or specific key. Remember that keys
371 * can be returned in any order.
372 */
373 if (pfs->name_key == 0) {
278ab2b2
MD
374 cluster = hammer2_cluster_lookup(cparent, &key_next,
375 0, (hammer2_key_t)-1,
376 0, &ddflag);
a864c5d9 377 } else if (pfs->name_key == (hammer2_key_t)-1) {
278ab2b2
MD
378 ipdata = &hammer2_cluster_data(rcluster)->ipdata;
379 cluster = hammer2_cluster_lookup(cparent, &key_next,
380 ipdata->name_key,
381 ipdata->name_key,
382 0, &ddflag);
383 ipdata = NULL; /* safety */
ae183399 384 } else {
278ab2b2
MD
385 cluster = hammer2_cluster_lookup(cparent, &key_next,
386 pfs->name_key, pfs->name_key,
387 0, &ddflag);
ae183399 388 }
278ab2b2 389 hammer2_inode_unlock_ex(ip->pmp->iroot, rcluster);
9b6b3df4 390
278ab2b2
MD
391 while (cluster &&
392 hammer2_cluster_type(cluster) != HAMMER2_BREF_TYPE_INODE) {
393 cluster = hammer2_cluster_next(cparent, cluster, &key_next,
394 key_next, (hammer2_key_t)-1,
395 0);
ae183399 396 }
278ab2b2 397 if (cluster) {
ae183399
MD
398 /*
399 * Load the data being returned by the ioctl.
400 */
278ab2b2 401 ipdata = &hammer2_cluster_data(cluster)->ipdata;
476d2aad
MD
402 pfs->name_key = ipdata->name_key;
403 pfs->pfs_type = ipdata->pfs_type;
404 pfs->pfs_clid = ipdata->pfs_clid;
405 pfs->pfs_fsid = ipdata->pfs_fsid;
406 KKASSERT(ipdata->name_len < sizeof(pfs->name));
407 bcopy(ipdata->filename, pfs->name, ipdata->name_len);
408 pfs->name[ipdata->name_len] = 0;
409 ipdata = NULL; /* safety */
ae183399
MD
410
411 /*
412 * Calculate the next field
413 */
414 do {
278ab2b2
MD
415 cluster = hammer2_cluster_next(cparent, cluster,
416 &key_next,
417 0, (hammer2_key_t)-1,
418 0);
419 } while (cluster &&
420 hammer2_cluster_type(cluster) !=
421 HAMMER2_BREF_TYPE_INODE);
422 if (cluster) {
423 ipdata = &hammer2_cluster_data(cluster)->ipdata;
424 pfs->name_next = ipdata->name_key;
425 hammer2_cluster_unlock(cluster);
ae183399
MD
426 } else {
427 pfs->name_next = (hammer2_key_t)-1;
428 }
429 } else {
430 pfs->name_next = (hammer2_key_t)-1;
431 error = ENOENT;
432 }
50456506 433 hammer2_inode_unlock_ex(hmp->spmp->iroot, cparent);
0dea3156 434
ae183399
MD
435 return (error);
436}
437
458ecb1b
MD
438/*
439 * Find a specific PFS by name
440 */
441static int
442hammer2_ioctl_pfs_lookup(hammer2_inode_t *ip, void *data)
443{
6a5f4fe6 444 const hammer2_inode_data_t *ipdata;
476d2aad
MD
445 hammer2_mount_t *hmp;
446 hammer2_ioc_pfs_t *pfs;
278ab2b2
MD
447 hammer2_cluster_t *cparent;
448 hammer2_cluster_t *cluster;
1897c66e 449 hammer2_key_t key_next;
458ecb1b 450 hammer2_key_t lhc;
476d2aad 451 int error;
278ab2b2 452 int ddflag;
458ecb1b
MD
453 size_t len;
454
476d2aad 455 error = 0;
58e43599 456 hmp = ip->pmp->iroot->cluster.focus->hmp; /* XXX */
476d2aad 457 pfs = data;
50456506 458 cparent = hammer2_inode_lock_sh(hmp->spmp->iroot);
458ecb1b
MD
459
460 pfs->name[sizeof(pfs->name) - 1] = 0;
461 len = strlen(pfs->name);
462 lhc = hammer2_dirhash(pfs->name, len);
463
278ab2b2
MD
464 cluster = hammer2_cluster_lookup(cparent, &key_next,
465 lhc, lhc + HAMMER2_DIRHASH_LOMASK,
466 HAMMER2_LOOKUP_SHARED, &ddflag);
467 while (cluster) {
468 if (hammer2_cluster_type(cluster) == HAMMER2_BREF_TYPE_INODE) {
469 ipdata = &hammer2_cluster_data(cluster)->ipdata;
470 if (ipdata->name_len == len &&
471 bcmp(ipdata->filename, pfs->name, len) == 0) {
472 break;
473 }
474 ipdata = NULL; /* safety */
458ecb1b 475 }
278ab2b2 476 cluster = hammer2_cluster_next(cparent, cluster, &key_next,
1897c66e
MD
477 key_next,
478 lhc + HAMMER2_DIRHASH_LOMASK,
278ab2b2 479 HAMMER2_LOOKUP_SHARED);
458ecb1b
MD
480 }
481
482 /*
483 * Load the data being returned by the ioctl.
484 */
278ab2b2
MD
485 if (cluster) {
486 ipdata = &hammer2_cluster_data(cluster)->ipdata;
476d2aad
MD
487 pfs->name_key = ipdata->name_key;
488 pfs->pfs_type = ipdata->pfs_type;
489 pfs->pfs_clid = ipdata->pfs_clid;
490 pfs->pfs_fsid = ipdata->pfs_fsid;
491 ipdata = NULL;
458ecb1b 492
278ab2b2 493 hammer2_cluster_unlock(cluster);
458ecb1b
MD
494 } else {
495 error = ENOENT;
496 }
50456506 497 hammer2_inode_unlock_sh(hmp->spmp->iroot, cparent);
7bed8d7e 498
458ecb1b
MD
499 return (error);
500}
501
ae183399
MD
502/*
503 * Create a new PFS under the super-root
504 */
505static int
506hammer2_ioctl_pfs_create(hammer2_inode_t *ip, void *data)
507{
476d2aad
MD
508 hammer2_inode_data_t *nipdata;
509 hammer2_mount_t *hmp;
510 hammer2_ioc_pfs_t *pfs;
511 hammer2_inode_t *nip;
278ab2b2 512 hammer2_cluster_t *ncluster;
0dea3156 513 hammer2_trans_t trans;
ae183399
MD
514 int error;
515
58e43599 516 hmp = ip->pmp->iroot->cluster.focus->hmp; /* XXX */
476d2aad
MD
517 pfs = data;
518 nip = NULL;
519
a864c5d9
MD
520 if (pfs->name[0] == 0)
521 return(EINVAL);
ae183399 522 pfs->name[sizeof(pfs->name) - 1] = 0; /* ensure 0-termination */
10252dc7 523
50456506
MD
524 hammer2_trans_init(&trans, ip->pmp, HAMMER2_TRANS_NEWINODE);
525 nip = hammer2_inode_create(&trans, hmp->spmp->iroot, NULL, NULL,
ae183399 526 pfs->name, strlen(pfs->name),
278ab2b2 527 &ncluster, &error);
ae183399 528 if (error == 0) {
278ab2b2 529 nipdata = hammer2_cluster_modify_ip(&trans, nip, ncluster,
4a59bd3e 530 HAMMER2_MODIFY_ASSERTNOCOPY);
476d2aad
MD
531 nipdata->pfs_type = pfs->pfs_type;
532 nipdata->pfs_clid = pfs->pfs_clid;
533 nipdata->pfs_fsid = pfs->pfs_fsid;
cdfd0a3e
MD
534
535 /*
536 * Do not allow compression on PFS's with the special name
537 * "boot", the boot loader can't decompress (yet).
538 */
539 if (strcmp(pfs->name, "boot") == 0)
540 nipdata->comp_algo = HAMMER2_COMP_AUTOZERO;
6a5f4fe6 541 hammer2_cluster_modsync(ncluster);
278ab2b2 542 hammer2_inode_unlock_ex(nip, ncluster);
ae183399 543 }
0dea3156 544 hammer2_trans_done(&trans);
278ab2b2 545
ae183399
MD
546 return (error);
547}
548
549/*
550 * Destroy an existing PFS under the super-root
551 */
552static int
553hammer2_ioctl_pfs_delete(hammer2_inode_t *ip, void *data)
554{
a5913bdf 555 hammer2_mount_t *hmp;
ae183399 556 hammer2_ioc_pfs_t *pfs = data;
0dea3156 557 hammer2_trans_t trans;
ae183399
MD
558 int error;
559
58e43599 560 hmp = ip->pmp->iroot->cluster.focus->hmp; /* XXX */
50456506
MD
561 hammer2_trans_init(&trans, ip->pmp, 0);
562 error = hammer2_unlink_file(&trans, hmp->spmp->iroot,
9797e933 563 pfs->name, strlen(pfs->name),
044541cd 564 2, NULL, NULL);
a864c5d9
MD
565 hammer2_trans_done(&trans);
566
567 return (error);
568}
569
570static int
571hammer2_ioctl_pfs_snapshot(hammer2_inode_t *ip, void *data)
572{
a864c5d9
MD
573 hammer2_ioc_pfs_t *pfs = data;
574 hammer2_trans_t trans;
278ab2b2 575 hammer2_cluster_t *cparent;
a864c5d9
MD
576 int error;
577
578 if (pfs->name[0] == 0)
579 return(EINVAL);
580 if (pfs->name[sizeof(pfs->name)-1] != 0)
581 return(EINVAL);
582
a7720be7
MD
583 hammer2_vfs_sync(ip->pmp->mp, MNT_WAIT);
584
50456506 585 hammer2_trans_init(&trans, ip->pmp, HAMMER2_TRANS_NEWINODE);
278ab2b2
MD
586 cparent = hammer2_inode_lock_ex(ip);
587 error = hammer2_cluster_snapshot(&trans, cparent, pfs);
588 hammer2_inode_unlock_ex(ip, cparent);
0dea3156
MD
589 hammer2_trans_done(&trans);
590
ae183399
MD
591 return (error);
592}
344d4f82
MD
593
594/*
595 * Retrieve the raw inode structure
596 */
597static int
598hammer2_ioctl_inode_get(hammer2_inode_t *ip, void *data)
599{
6a5f4fe6
MD
600 const hammer2_inode_data_t *ipdata;
601 hammer2_ioc_inode_t *ino;
278ab2b2 602 hammer2_cluster_t *cparent;
344d4f82 603
6a5f4fe6
MD
604 ino = data;
605
278ab2b2
MD
606 cparent = hammer2_inode_lock_sh(ip);
607 ipdata = &hammer2_cluster_data(cparent)->ipdata;
608 ino->ip_data = *ipdata;
26b047fa 609 ino->kdata = ip;
278ab2b2 610 hammer2_inode_unlock_sh(ip, cparent);
0dea3156 611
344d4f82
MD
612 return (0);
613}
614
f481450f
MD
615/*
616 * Set various parameters in an inode which cannot be set through
617 * normal filesystem VNOPS.
618 */
344d4f82
MD
619static int
620hammer2_ioctl_inode_set(hammer2_inode_t *ip, void *data)
621{
6a5f4fe6
MD
622 const hammer2_inode_data_t *ripdata;
623 hammer2_inode_data_t *wipdata;
344d4f82 624 hammer2_ioc_inode_t *ino = data;
278ab2b2 625 hammer2_cluster_t *cparent;
355d67fc 626 hammer2_trans_t trans;
f481450f 627 int error = 0;
6a5f4fe6 628 int dosync = 0;
344d4f82 629
50456506 630 hammer2_trans_init(&trans, ip->pmp, 0);
278ab2b2 631 cparent = hammer2_inode_lock_ex(ip);
6a5f4fe6 632 ripdata = &hammer2_cluster_data(cparent)->ipdata;
f481450f 633
6a5f4fe6
MD
634 if (ino->ip_data.comp_algo != ripdata->comp_algo) {
635 wipdata = hammer2_cluster_modify_ip(&trans, ip, cparent, 0);
636 wipdata->comp_algo = ino->ip_data.comp_algo;
637 ripdata = wipdata; /* safety */
638 dosync = 1;
f481450f 639 }
355d67fc
MD
640 ino->kdata = ip;
641
f481450f 642 /* Ignore these flags for now...*/
344d4f82
MD
643 if (ino->flags & HAMMER2IOC_INODE_FLAG_IQUOTA) {
644 }
645 if (ino->flags & HAMMER2IOC_INODE_FLAG_DQUOTA) {
646 }
647 if (ino->flags & HAMMER2IOC_INODE_FLAG_COPIES) {
648 }
6a5f4fe6
MD
649 if (dosync)
650 hammer2_cluster_modsync(cparent);
355d67fc 651 hammer2_trans_done(&trans);
278ab2b2 652 hammer2_inode_unlock_ex(ip, cparent);
0dea3156 653
344d4f82
MD
654 return (error);
655}