2 * Copyright (c) 2011-2015 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
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.
45 static int hammer2_ioctl_version_get(hammer2_inode_t *ip, void *data);
46 static int hammer2_ioctl_recluster(hammer2_inode_t *ip, void *data);
47 static int hammer2_ioctl_remote_scan(hammer2_inode_t *ip, void *data);
48 static int hammer2_ioctl_remote_add(hammer2_inode_t *ip, void *data);
49 static int hammer2_ioctl_remote_del(hammer2_inode_t *ip, void *data);
50 static int hammer2_ioctl_remote_rep(hammer2_inode_t *ip, void *data);
51 static int hammer2_ioctl_socket_get(hammer2_inode_t *ip, void *data);
52 static int hammer2_ioctl_socket_set(hammer2_inode_t *ip, void *data);
53 static int hammer2_ioctl_pfs_get(hammer2_inode_t *ip, void *data);
54 static int hammer2_ioctl_pfs_lookup(hammer2_inode_t *ip, void *data);
55 static int hammer2_ioctl_pfs_create(hammer2_inode_t *ip, void *data);
56 static int hammer2_ioctl_pfs_snapshot(hammer2_inode_t *ip, void *data);
57 static int hammer2_ioctl_pfs_delete(hammer2_inode_t *ip, void *data);
58 static int hammer2_ioctl_inode_get(hammer2_inode_t *ip, void *data);
59 static int hammer2_ioctl_inode_set(hammer2_inode_t *ip, void *data);
60 static int hammer2_ioctl_debug_dump(hammer2_inode_t *ip);
61 //static int hammer2_ioctl_inode_comp_set(hammer2_inode_t *ip, void *data);
62 //static int hammer2_ioctl_inode_comp_rec_set(hammer2_inode_t *ip, void *data);
63 //static int hammer2_ioctl_inode_comp_rec_set2(hammer2_inode_t *ip, void *data);
64 static int hammer2_ioctl_bulkfree_scan(hammer2_inode_t *ip, void *data);
67 hammer2_ioctl(hammer2_inode_t *ip, u_long com, void *data, int fflag,
73 * Standard root cred checks, will be selectively ignored below
74 * for ioctls that do not require root creds.
76 error = priv_check_cred(cred, PRIV_HAMMER_IOCTL, 0);
79 case HAMMER2IOC_VERSION_GET:
80 error = hammer2_ioctl_version_get(ip, data);
82 case HAMMER2IOC_RECLUSTER:
84 error = hammer2_ioctl_recluster(ip, data);
86 case HAMMER2IOC_REMOTE_SCAN:
88 error = hammer2_ioctl_remote_scan(ip, data);
90 case HAMMER2IOC_REMOTE_ADD:
92 error = hammer2_ioctl_remote_add(ip, data);
94 case HAMMER2IOC_REMOTE_DEL:
96 error = hammer2_ioctl_remote_del(ip, data);
98 case HAMMER2IOC_REMOTE_REP:
100 error = hammer2_ioctl_remote_rep(ip, data);
102 case HAMMER2IOC_SOCKET_GET:
104 error = hammer2_ioctl_socket_get(ip, data);
106 case HAMMER2IOC_SOCKET_SET:
108 error = hammer2_ioctl_socket_set(ip, data);
110 case HAMMER2IOC_PFS_GET:
112 error = hammer2_ioctl_pfs_get(ip, data);
114 case HAMMER2IOC_PFS_LOOKUP:
116 error = hammer2_ioctl_pfs_lookup(ip, data);
118 case HAMMER2IOC_PFS_CREATE:
120 error = hammer2_ioctl_pfs_create(ip, data);
122 case HAMMER2IOC_PFS_DELETE:
124 error = hammer2_ioctl_pfs_delete(ip, data);
126 case HAMMER2IOC_PFS_SNAPSHOT:
128 error = hammer2_ioctl_pfs_snapshot(ip, data);
130 case HAMMER2IOC_INODE_GET:
131 error = hammer2_ioctl_inode_get(ip, data);
133 case HAMMER2IOC_INODE_SET:
135 error = hammer2_ioctl_inode_set(ip, data);
137 case HAMMER2IOC_BULKFREE_SCAN:
138 error = hammer2_ioctl_bulkfree_scan(ip, data);
140 case HAMMER2IOC_BULKFREE_ASYNC:
141 error = hammer2_ioctl_bulkfree_scan(ip, NULL);
143 /*case HAMMER2IOC_INODE_COMP_SET:
144 error = hammer2_ioctl_inode_comp_set(ip, data);
146 case HAMMER2IOC_INODE_COMP_REC_SET:
147 error = hammer2_ioctl_inode_comp_rec_set(ip, data);
149 case HAMMER2IOC_INODE_COMP_REC_SET2:
150 error = hammer2_ioctl_inode_comp_rec_set2(ip, data);
152 case HAMMER2IOC_DEBUG_DUMP:
153 error = hammer2_ioctl_debug_dump(ip);
163 * Retrieve version and basic info
166 hammer2_ioctl_version_get(hammer2_inode_t *ip, void *data)
168 hammer2_ioc_version_t *version = data;
171 hmp = ip->pmp->pfs_hmps[0];
173 version->version = hmp->voldata.version;
175 version->version = -1;
180 hammer2_ioctl_recluster(hammer2_inode_t *ip, void *data)
182 hammer2_ioc_recluster_t *recl = data;
183 struct vnode *vproot;
185 hammer2_cluster_t *cluster;
188 fp = holdfp(curproc->p_fd, recl->fd, -1);
190 error = VFS_ROOT(ip->pmp->mp, &vproot);
192 cluster = &ip->pmp->iroot->cluster;
193 kprintf("reconnect to cluster: nc=%d focus=%p\n",
194 cluster->nchains, cluster->focus);
195 if (cluster->nchains != 1 || cluster->focus == NULL) {
196 kprintf("not a local device mount\n");
199 hammer2_cluster_reconnect(cluster->focus->hmp,
213 * Retrieve information about a remote
216 hammer2_ioctl_remote_scan(hammer2_inode_t *ip, void *data)
219 hammer2_ioc_remote_t *remote = data;
220 int copyid = remote->copyid;
222 hmp = ip->pmp->pfs_hmps[0];
226 if (copyid < 0 || copyid >= HAMMER2_COPYID_COUNT)
229 hammer2_voldata_lock(hmp);
230 remote->copy1 = hmp->voldata.copyinfo[copyid];
231 hammer2_voldata_unlock(hmp);
234 * Adjust nextid (GET only)
236 while (++copyid < HAMMER2_COPYID_COUNT &&
237 hmp->voldata.copyinfo[copyid].copyid == 0) {
240 if (copyid == HAMMER2_COPYID_COUNT)
243 remote->nextid = copyid;
249 * Add new remote entry
252 hammer2_ioctl_remote_add(hammer2_inode_t *ip, void *data)
254 hammer2_ioc_remote_t *remote = data;
255 hammer2_pfs_t *pmp = ip->pmp;
257 int copyid = remote->copyid;
260 hmp = pmp->pfs_hmps[0];
263 if (copyid >= HAMMER2_COPYID_COUNT)
266 hammer2_voldata_lock(hmp);
268 for (copyid = 1; copyid < HAMMER2_COPYID_COUNT; ++copyid) {
269 if (hmp->voldata.copyinfo[copyid].copyid == 0)
272 if (copyid == HAMMER2_COPYID_COUNT) {
277 hammer2_voldata_modify(hmp);
278 remote->copy1.copyid = copyid;
279 hmp->voldata.copyinfo[copyid] = remote->copy1;
280 hammer2_volconf_update(hmp, copyid);
282 hammer2_voldata_unlock(hmp);
287 * Delete existing remote entry
290 hammer2_ioctl_remote_del(hammer2_inode_t *ip, void *data)
292 hammer2_ioc_remote_t *remote = data;
293 hammer2_pfs_t *pmp = ip->pmp;
295 int copyid = remote->copyid;
298 hmp = pmp->pfs_hmps[0];
301 if (copyid >= HAMMER2_COPYID_COUNT)
303 remote->copy1.path[sizeof(remote->copy1.path) - 1] = 0;
304 hammer2_voldata_lock(hmp);
306 for (copyid = 1; copyid < HAMMER2_COPYID_COUNT; ++copyid) {
307 if (hmp->voldata.copyinfo[copyid].copyid == 0)
309 if (strcmp(remote->copy1.path,
310 hmp->voldata.copyinfo[copyid].path) == 0) {
314 if (copyid == HAMMER2_COPYID_COUNT) {
319 hammer2_voldata_modify(hmp);
320 hmp->voldata.copyinfo[copyid].copyid = 0;
321 hammer2_volconf_update(hmp, copyid);
323 hammer2_voldata_unlock(hmp);
328 * Replace existing remote entry
331 hammer2_ioctl_remote_rep(hammer2_inode_t *ip, void *data)
333 hammer2_ioc_remote_t *remote = data;
335 int copyid = remote->copyid;
337 hmp = ip->pmp->pfs_hmps[0];
340 if (copyid < 0 || copyid >= HAMMER2_COPYID_COUNT)
343 hammer2_voldata_lock(hmp);
344 hammer2_voldata_modify(hmp);
345 /*hammer2_volconf_update(hmp, copyid);*/
346 hammer2_voldata_unlock(hmp);
352 * Retrieve communications socket
355 hammer2_ioctl_socket_get(hammer2_inode_t *ip, void *data)
361 * Set communications socket for connection
364 hammer2_ioctl_socket_set(hammer2_inode_t *ip, void *data)
366 hammer2_ioc_remote_t *remote = data;
368 int copyid = remote->copyid;
370 hmp = ip->pmp->pfs_hmps[0];
373 if (copyid < 0 || copyid >= HAMMER2_COPYID_COUNT)
376 hammer2_voldata_lock(hmp);
377 hammer2_voldata_unlock(hmp);
383 * Used to scan and retrieve PFS information. PFS's are directories under
386 * To scan PFSs pass name_key=0. The function will scan for the next
387 * PFS and set all fields, as well as set name_next to the next key.
388 * When no PFSs remain, name_next is set to (hammer2_key_t)-1.
390 * To retrieve a particular PFS by key, specify the key but note that
391 * the ioctl will return the lowest key >= specified_key, so the caller
392 * must verify the key.
394 * To retrieve the PFS associated with the file descriptor, pass
395 * name_key set to (hammer2_key_t)-1.
398 hammer2_ioctl_pfs_get(hammer2_inode_t *ip, void *data)
400 const hammer2_inode_data_t *ripdata;
402 hammer2_ioc_pfs_t *pfs;
403 hammer2_chain_t *parent;
404 hammer2_chain_t *chain;
405 hammer2_key_t key_next;
406 hammer2_key_t save_key;
409 hmp = ip->pmp->pfs_hmps[0];
414 save_key = pfs->name_key;
420 if (save_key == (hammer2_key_t)-1) {
421 hammer2_inode_lock(ip->pmp->iroot, 0);
423 chain = hammer2_inode_chain(ip->pmp->iroot, 0,
424 HAMMER2_RESOLVE_ALWAYS |
425 HAMMER2_RESOLVE_SHARED);
427 hammer2_inode_lock(hmp->spmp->iroot, 0);
428 parent = hammer2_inode_chain(hmp->spmp->iroot, 0,
429 HAMMER2_RESOLVE_ALWAYS |
430 HAMMER2_RESOLVE_SHARED);
431 chain = hammer2_chain_lookup(&parent, &key_next,
432 pfs->name_key, HAMMER2_KEY_MAX,
433 HAMMER2_LOOKUP_SHARED);
440 if (chain->bref.type == HAMMER2_BREF_TYPE_INODE)
442 if (parent == NULL) {
443 hammer2_chain_unlock(chain);
444 hammer2_chain_drop(chain);
448 chain = hammer2_chain_next(&parent, chain, &key_next,
449 key_next, HAMMER2_KEY_MAX,
450 HAMMER2_LOOKUP_SHARED);
454 * Load the data being returned by the ioctl.
457 ripdata = &chain->data->ipdata;
458 pfs->name_key = ripdata->meta.name_key;
459 pfs->pfs_type = ripdata->meta.pfs_type;
460 pfs->pfs_subtype = ripdata->meta.pfs_subtype;
461 pfs->pfs_clid = ripdata->meta.pfs_clid;
462 pfs->pfs_fsid = ripdata->meta.pfs_fsid;
463 KKASSERT(ripdata->meta.name_len < sizeof(pfs->name));
464 bcopy(ripdata->filename, pfs->name, ripdata->meta.name_len);
465 pfs->name[ripdata->meta.name_len] = 0;
466 ripdata = NULL; /* safety */
469 * Calculate name_next, if any.
471 if (parent == NULL) {
472 pfs->name_next = (hammer2_key_t)-1;
474 chain = hammer2_chain_next(&parent, chain, &key_next,
475 key_next, HAMMER2_KEY_MAX,
476 HAMMER2_LOOKUP_SHARED);
478 pfs->name_next = chain->bref.key;
480 pfs->name_next = (hammer2_key_t)-1;
483 pfs->name_next = (hammer2_key_t)-1;
491 hammer2_chain_unlock(chain);
492 hammer2_chain_drop(chain);
495 hammer2_chain_unlock(parent);
496 hammer2_chain_drop(parent);
498 if (save_key == (hammer2_key_t)-1) {
499 hammer2_inode_unlock(ip->pmp->iroot);
501 hammer2_inode_unlock(hmp->spmp->iroot);
508 * Find a specific PFS by name
511 hammer2_ioctl_pfs_lookup(hammer2_inode_t *ip, void *data)
513 const hammer2_inode_data_t *ripdata;
515 hammer2_ioc_pfs_t *pfs;
516 hammer2_chain_t *parent;
517 hammer2_chain_t *chain;
518 hammer2_key_t key_next;
523 hmp = ip->pmp->pfs_hmps[0];
530 hammer2_inode_lock(hmp->spmp->iroot, HAMMER2_RESOLVE_SHARED);
531 parent = hammer2_inode_chain(hmp->spmp->iroot, 0,
532 HAMMER2_RESOLVE_ALWAYS |
533 HAMMER2_RESOLVE_SHARED);
535 pfs->name[sizeof(pfs->name) - 1] = 0;
536 len = strlen(pfs->name);
537 lhc = hammer2_dirhash(pfs->name, len);
539 chain = hammer2_chain_lookup(&parent, &key_next,
540 lhc, lhc + HAMMER2_DIRHASH_LOMASK,
541 HAMMER2_LOOKUP_SHARED);
543 if (hammer2_chain_dirent_test(chain, pfs->name, len))
545 chain = hammer2_chain_next(&parent, chain, &key_next,
547 lhc + HAMMER2_DIRHASH_LOMASK,
548 HAMMER2_LOOKUP_SHARED);
552 * Load the data being returned by the ioctl.
555 KKASSERT(chain->bref.type == HAMMER2_BREF_TYPE_INODE);
556 ripdata = &chain->data->ipdata;
557 pfs->name_key = ripdata->meta.name_key;
558 pfs->pfs_type = ripdata->meta.pfs_type;
559 pfs->pfs_subtype = ripdata->meta.pfs_subtype;
560 pfs->pfs_clid = ripdata->meta.pfs_clid;
561 pfs->pfs_fsid = ripdata->meta.pfs_fsid;
564 hammer2_chain_unlock(chain);
565 hammer2_chain_drop(chain);
570 hammer2_chain_unlock(parent);
571 hammer2_chain_drop(parent);
573 hammer2_inode_unlock(hmp->spmp->iroot);
579 * Create a new PFS under the super-root
582 hammer2_ioctl_pfs_create(hammer2_inode_t *ip, void *data)
584 hammer2_inode_data_t *nipdata;
585 hammer2_chain_t *nchain;
587 hammer2_dev_t *force_local;
588 hammer2_ioc_pfs_t *pfs;
589 hammer2_inode_t *nip;
593 hmp = ip->pmp->pfs_hmps[0]; /* XXX */
600 if (pfs->name[0] == 0)
602 pfs->name[sizeof(pfs->name) - 1] = 0; /* ensure 0-termination */
604 if (hammer2_ioctl_pfs_lookup(ip, pfs) == 0)
607 hammer2_trans_init(hmp->spmp, 0);
608 mtid = hammer2_trans_sub(hmp->spmp);
609 nip = hammer2_inode_create(hmp->spmp->iroot, hmp->spmp->iroot,
611 pfs->name, strlen(pfs->name), 0,
612 1, HAMMER2_OBJTYPE_DIRECTORY, 0,
613 HAMMER2_INSERT_PFSROOT, &error);
615 hammer2_inode_modify(nip);
616 nchain = hammer2_inode_chain(nip, 0, HAMMER2_RESOLVE_ALWAYS);
617 hammer2_chain_modify(nchain, mtid, 0, 0);
618 nipdata = &nchain->data->ipdata;
620 nip->meta.pfs_type = pfs->pfs_type;
621 nip->meta.pfs_subtype = pfs->pfs_subtype;
622 nip->meta.pfs_clid = pfs->pfs_clid;
623 nip->meta.pfs_fsid = pfs->pfs_fsid;
624 nip->meta.op_flags |= HAMMER2_OPFLAG_PFSROOT;
627 * Set default compression and check algorithm. This
628 * can be changed later.
630 * Do not allow compression on PFS's with the special name
631 * "boot", the boot loader can't decompress (yet).
633 nip->meta.comp_algo =
634 HAMMER2_ENC_ALGO(HAMMER2_COMP_NEWFS_DEFAULT);
635 nip->meta.check_algo =
636 HAMMER2_ENC_ALGO( HAMMER2_CHECK_XXHASH64);
638 if (strcasecmp(pfs->name, "boot") == 0) {
639 nip->meta.comp_algo =
640 HAMMER2_ENC_ALGO(HAMMER2_COMP_AUTOZERO);
644 * Super-root isn't mounted, fsync it
646 hammer2_chain_unlock(nchain);
647 hammer2_inode_ref(nip);
648 hammer2_inode_unlock(nip);
649 hammer2_inode_chain_sync(nip);
650 hammer2_inode_drop(nip);
653 * We still have a ref on the chain, relock and associate
654 * with an appropriate PFS.
656 force_local = (hmp->hflags & HMNT2_LOCAL) ? hmp : NULL;
658 hammer2_chain_lock(nchain, HAMMER2_RESOLVE_ALWAYS);
659 nipdata = &nchain->data->ipdata;
660 kprintf("ADD LOCAL PFS (IOCTL): %s\n", nipdata->filename);
661 hammer2_pfsalloc(nchain, nipdata,
662 nchain->bref.modify_tid, force_local);
664 hammer2_chain_unlock(nchain);
665 hammer2_chain_drop(nchain);
668 hammer2_trans_done(hmp->spmp);
674 * Destroy an existing PFS under the super-root
677 hammer2_ioctl_pfs_delete(hammer2_inode_t *ip, void *data)
679 hammer2_ioc_pfs_t *pfs = data;
683 hammer2_xop_unlink_t *xop;
684 hammer2_inode_t *dip;
685 hammer2_inode_t *iroot;
690 * The PFS should be probed, so we should be able to
691 * locate it. We only delete the PFS from the
692 * specific H2 block device (hmp), not all of
693 * them. We must remove the PFS from the cluster
694 * before we can destroy it.
696 hmp = ip->pmp->pfs_hmps[0];
700 pfs->name[sizeof(pfs->name) - 1] = 0; /* ensure termination */
702 lockmgr(&hammer2_mntlk, LK_EXCLUSIVE);
704 TAILQ_FOREACH(pmp, &hammer2_pfslist, mntentry) {
705 for (i = 0; i < HAMMER2_MAXCLUSTER; ++i) {
706 if (pmp->pfs_hmps[i] != hmp)
708 if (pmp->pfs_names[i] &&
709 strcmp(pmp->pfs_names[i], pfs->name) == 0) {
713 if (i != HAMMER2_MAXCLUSTER)
718 lockmgr(&hammer2_mntlk, LK_RELEASE);
723 * Ok, we found the pmp and we have the index. Permanently remove
724 * the PFS from the cluster
727 kprintf("FOUND PFS %s CLINDEX %d\n", pfs->name, i);
728 hammer2_pfsdealloc(pmp, i, 1);
730 lockmgr(&hammer2_mntlk, LK_RELEASE);
733 * Now destroy the PFS under its device using the per-device
738 hammer2_trans_init(spmp, 0);
739 hammer2_inode_lock(dip, 0);
741 xop = hammer2_xop_alloc(dip, HAMMER2_XOP_MODIFYING);
742 hammer2_xop_setname(&xop->head, pfs->name, strlen(pfs->name));
744 xop->dopermanent = 2 | 1; /* FORCE | PERMANENT */
745 hammer2_xop_start(&xop->head, hammer2_xop_unlink);
747 error = hammer2_xop_collect(&xop->head, 0);
749 hammer2_inode_unlock(dip);
753 ip = hammer2_inode_get(dip->pmp, dip, &xop->head.cluster, -1);
754 hammer2_xop_retire(&xop->head, HAMMER2_XOPMASK_VOP);
756 hammer2_inode_unlink_finisher(ip, 0);
757 hammer2_inode_unlock(ip);
760 hammer2_xop_retire(&xop->head, HAMMER2_XOPMASK_VOP);
763 hammer2_xop_retire(&xop->head, HAMMER2_XOPMASK_VOP);
765 hammer2_trans_done(spmp);
771 hammer2_ioctl_pfs_snapshot(hammer2_inode_t *ip, void *data)
773 hammer2_ioc_pfs_t *pfs = data;
776 hammer2_chain_t *chain;
780 if (pfs->name[0] == 0)
782 if (pfs->name[sizeof(pfs->name)-1] != 0)
788 hmp = pmp->pfs_hmps[0];
792 lockmgr(&hmp->bulklk, LK_EXCLUSIVE);
794 hammer2_vfs_sync(pmp->mp, MNT_WAIT);
796 hammer2_trans_init(pmp, HAMMER2_TRANS_ISFLUSH);
797 mtid = hammer2_trans_sub(pmp);
798 hammer2_inode_lock(ip, 0);
799 hammer2_inode_modify(ip);
800 ip->meta.pfs_lsnap_tid = mtid;
802 /* XXX cluster it! */
803 chain = hammer2_inode_chain(ip, 0, HAMMER2_RESOLVE_ALWAYS);
804 error = hammer2_chain_snapshot(chain, pfs, mtid);
805 hammer2_chain_unlock(chain);
806 hammer2_chain_drop(chain);
808 hammer2_inode_unlock(ip);
809 hammer2_trans_done(pmp);
811 lockmgr(&hmp->bulklk, LK_RELEASE);
817 * Retrieve the raw inode structure, non-inclusive of node-specific data.
820 hammer2_ioctl_inode_get(hammer2_inode_t *ip, void *data)
822 hammer2_ioc_inode_t *ino;
823 hammer2_chain_t *chain;
830 hammer2_inode_lock(ip, HAMMER2_RESOLVE_SHARED);
832 ino->inode_count = 0;
833 for (i = 0; i < ip->cluster.nchains; ++i) {
834 if ((chain = ip->cluster.array[i].chain) != NULL) {
835 if (ino->data_count <
836 chain->bref.embed.stats.data_count) {
838 chain->bref.embed.stats.data_count;
840 if (ino->inode_count <
841 chain->bref.embed.stats.inode_count) {
843 chain->bref.embed.stats.inode_count;
847 bzero(&ino->ip_data, sizeof(ino->ip_data));
848 ino->ip_data.meta = ip->meta;
850 hammer2_inode_unlock(ip);
856 * Set various parameters in an inode which cannot be set through
857 * normal filesystem VNOPS.
860 hammer2_ioctl_inode_set(hammer2_inode_t *ip, void *data)
862 hammer2_ioc_inode_t *ino = data;
865 hammer2_trans_init(ip->pmp, 0);
866 hammer2_inode_lock(ip, 0);
868 if ((ino->flags & HAMMER2IOC_INODE_FLAG_CHECK) &&
869 ip->meta.check_algo != ino->ip_data.meta.check_algo) {
870 hammer2_inode_modify(ip);
871 ip->meta.check_algo = ino->ip_data.meta.check_algo;
873 if ((ino->flags & HAMMER2IOC_INODE_FLAG_COMP) &&
874 ip->meta.comp_algo != ino->ip_data.meta.comp_algo) {
875 hammer2_inode_modify(ip);
876 ip->meta.comp_algo = ino->ip_data.meta.comp_algo;
880 /* Ignore these flags for now...*/
881 if ((ino->flags & HAMMER2IOC_INODE_FLAG_IQUOTA) &&
882 ip->meta.inode_quota != ino->ip_data.meta.inode_quota) {
883 hammer2_inode_modify(ip);
884 ip->meta.inode_quota = ino->ip_data.meta.inode_quota;
886 if ((ino->flags & HAMMER2IOC_INODE_FLAG_DQUOTA) &&
887 ip->meta.data_quota != ino->ip_data.meta.data_quota) {
888 hammer2_inode_modify(ip);
889 ip->meta.data_quota = ino->ip_data.meta.data_quota;
891 if ((ino->flags & HAMMER2IOC_INODE_FLAG_COPIES) &&
892 ip->meta.ncopies != ino->ip_data.meta.ncopies) {
893 hammer2_inode_modify(ip);
894 ip->meta.ncopies = ino->ip_data.meta.ncopies;
896 hammer2_inode_unlock(ip);
897 hammer2_trans_done(ip->pmp);
904 hammer2_ioctl_debug_dump(hammer2_inode_t *ip)
906 hammer2_chain_t *chain;
910 for (i = 0; i < ip->cluster.nchains; ++i) {
911 chain = ip->cluster.array[i].chain;
914 hammer2_dump_chain(chain, 0, &count, 'i');
920 * Executes one flush/free pass per call. If trying to recover
921 * data we just freed up a moment ago it can take up to six passes
922 * to fully free the blocks. Note that passes occur automatically based
923 * on free space as the storage fills up, but manual passes may be needed
924 * if storage becomes almost completely full.
928 hammer2_ioctl_bulkfree_scan(hammer2_inode_t *ip, void *data)
930 hammer2_ioc_bulkfree_t *bfi = data;
933 hammer2_chain_t *vchain;
939 hmp = pmp->pfs_hmps[0];
946 * Bulkfree has to be serialized to guarantee at least one sync
947 * inbetween bulkfrees.
949 error = lockmgr(&hmp->bflock, LK_EXCLUSIVE | LK_PCATCH);
954 * sync the filesystem and obtain a snapshot of the synchronized
955 * hmp volume header. We treat the snapshot as an independent
958 hammer2_vfs_sync(pmp->mp, MNT_WAIT);
959 vchain = hammer2_chain_bulksnap(hmp);
962 * Normal filesystem operations will not interfere with the
963 * synchronized block hierarchy and can run concurrent with the
966 hammer2_trans_init(pmp, 0);
968 hammer2_thr_freeze(&hmp->bfthr);
969 error = hammer2_bulkfree_pass(hmp, vchain, bfi);
970 hammer2_thr_unfreeze(&hmp->bfthr);
972 hammer2_chain_bulkdrop(vchain);
973 hammer2_trans_done(pmp);
975 lockmgr(&hmp->bflock, LK_RELEASE);
977 return (hammer2_error_to_errno(error));