3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 */
24
25 #include <sys/types.h>
26 #include <sys/param.h>
27 #include <sys/time.h>
28 #include <sys/systm.h>
29 #include <sys/sysmacros.h>
30 #include <sys/resource.h>
31 #include <sys/vfs.h>
32 #include <sys/vnode.h>
33 #include <sys/file.h>
34 #include <sys/mode.h>
35 #include <sys/kmem.h>
36 #include <sys/uio.h>
37 #include <sys/pathname.h>
38 #include <sys/cmn_err.h>
39 #include <sys/errno.h>
40 #include <sys/stat.h>
41 #include <sys/unistd.h>
42 #include <sys/sunddi.h>
437 *
438 * When dealing with the unlinked set, we dmu_tx_hold_zap(), but we
439 * don't specify the name of the entry that we will be manipulating. We
440 * also fib and say that we won't be adding any new entries to the
441 * unlinked set, even though we might (this is to lower the minimum file
442 * size that can be deleted in a full filesystem). So on the small
443 * chance that the nlink list is using a fat zap (ie. has more than
444 * 2000 entries), we *may* not pre-read a block that's needed.
445 * Therefore it is remotely possible for some of the assertions
446 * regarding the unlinked set below to fail due to i/o error. On a
447 * nondebug system, this will result in the space being leaked.
448 */
449 void
450 zfs_unlinked_add(znode_t *zp, dmu_tx_t *tx)
451 {
452 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
453
454 ASSERT(zp->z_unlinked);
455 ASSERT(zp->z_links == 0);
456
457 VERIFY3U(0, ==,
458 zap_add_int(zfsvfs->z_os, zfsvfs->z_unlinkedobj, zp->z_id, tx));
459 }
460
461 /*
462 * Clean up any znodes that had no links when we either crashed or
463 * (force) umounted the file system.
464 */
465 void
466 zfs_unlinked_drain(zfsvfs_t *zfsvfs)
467 {
468 zap_cursor_t zc;
469 zap_attribute_t zap;
470 dmu_object_info_t doi;
471 znode_t *zp;
472 int error;
473
474 /*
475 * Interate over the contents of the unlinked set.
476 */
477 for (zap_cursor_init(&zc, zfsvfs->z_os, zfsvfs->z_unlinkedobj);
478 zap_cursor_retrieve(&zc, &zap) == 0;
654 * which point we'll call zfs_unlinked_drain() to process it).
655 */
656 dmu_tx_abort(tx);
657 zfs_znode_dmu_fini(zp);
658 zfs_znode_free(zp);
659 goto out;
660 }
661
662 if (xzp) {
663 ASSERT(error == 0);
664 mutex_enter(&xzp->z_lock);
665 xzp->z_unlinked = B_TRUE; /* mark xzp for deletion */
666 xzp->z_links = 0; /* no more links to it */
667 VERIFY(0 == sa_update(xzp->z_sa_hdl, SA_ZPL_LINKS(zfsvfs),
668 &xzp->z_links, sizeof (xzp->z_links), tx));
669 mutex_exit(&xzp->z_lock);
670 zfs_unlinked_add(xzp, tx);
671 }
672
673 /* Remove this znode from the unlinked set */
674 VERIFY3U(0, ==,
675 zap_remove_int(zfsvfs->z_os, zfsvfs->z_unlinkedobj, zp->z_id, tx));
676
677 zfs_znode_delete(zp, tx);
678
679 dmu_tx_commit(tx);
680 out:
681 if (xzp)
682 VN_RELE(ZTOV(xzp));
683 }
684
685 static uint64_t
686 zfs_dirent(znode_t *zp, uint64_t mode)
687 {
688 uint64_t de = zp->z_id;
689
690 if (zp->z_zfsvfs->z_version >= ZPL_VERSION_DIRENT_TYPE)
691 de |= IFTODT(mode) << 60;
692 return (de);
693 }
694
695 /*
|
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012 by Delphix. All rights reserved.
24 */
25
26 #include <sys/types.h>
27 #include <sys/param.h>
28 #include <sys/time.h>
29 #include <sys/systm.h>
30 #include <sys/sysmacros.h>
31 #include <sys/resource.h>
32 #include <sys/vfs.h>
33 #include <sys/vnode.h>
34 #include <sys/file.h>
35 #include <sys/mode.h>
36 #include <sys/kmem.h>
37 #include <sys/uio.h>
38 #include <sys/pathname.h>
39 #include <sys/cmn_err.h>
40 #include <sys/errno.h>
41 #include <sys/stat.h>
42 #include <sys/unistd.h>
43 #include <sys/sunddi.h>
438 *
439 * When dealing with the unlinked set, we dmu_tx_hold_zap(), but we
440 * don't specify the name of the entry that we will be manipulating. We
441 * also fib and say that we won't be adding any new entries to the
442 * unlinked set, even though we might (this is to lower the minimum file
443 * size that can be deleted in a full filesystem). So on the small
444 * chance that the nlink list is using a fat zap (ie. has more than
445 * 2000 entries), we *may* not pre-read a block that's needed.
446 * Therefore it is remotely possible for some of the assertions
447 * regarding the unlinked set below to fail due to i/o error. On a
448 * nondebug system, this will result in the space being leaked.
449 */
450 void
451 zfs_unlinked_add(znode_t *zp, dmu_tx_t *tx)
452 {
453 zfsvfs_t *zfsvfs = zp->z_zfsvfs;
454
455 ASSERT(zp->z_unlinked);
456 ASSERT(zp->z_links == 0);
457
458 VERIFY0(zap_add_int(zfsvfs->z_os, zfsvfs->z_unlinkedobj,
459 zp->z_id, tx));
460 }
461
462 /*
463 * Clean up any znodes that had no links when we either crashed or
464 * (force) umounted the file system.
465 */
466 void
467 zfs_unlinked_drain(zfsvfs_t *zfsvfs)
468 {
469 zap_cursor_t zc;
470 zap_attribute_t zap;
471 dmu_object_info_t doi;
472 znode_t *zp;
473 int error;
474
475 /*
476 * Interate over the contents of the unlinked set.
477 */
478 for (zap_cursor_init(&zc, zfsvfs->z_os, zfsvfs->z_unlinkedobj);
479 zap_cursor_retrieve(&zc, &zap) == 0;
655 * which point we'll call zfs_unlinked_drain() to process it).
656 */
657 dmu_tx_abort(tx);
658 zfs_znode_dmu_fini(zp);
659 zfs_znode_free(zp);
660 goto out;
661 }
662
663 if (xzp) {
664 ASSERT(error == 0);
665 mutex_enter(&xzp->z_lock);
666 xzp->z_unlinked = B_TRUE; /* mark xzp for deletion */
667 xzp->z_links = 0; /* no more links to it */
668 VERIFY(0 == sa_update(xzp->z_sa_hdl, SA_ZPL_LINKS(zfsvfs),
669 &xzp->z_links, sizeof (xzp->z_links), tx));
670 mutex_exit(&xzp->z_lock);
671 zfs_unlinked_add(xzp, tx);
672 }
673
674 /* Remove this znode from the unlinked set */
675 VERIFY0(zap_remove_int(zfsvfs->z_os, zfsvfs->z_unlinkedobj,
676 xzp->z_id, tx));
677
678 zfs_znode_delete(zp, tx);
679
680 dmu_tx_commit(tx);
681 out:
682 if (xzp)
683 VN_RELE(ZTOV(xzp));
684 }
685
686 static uint64_t
687 zfs_dirent(znode_t *zp, uint64_t mode)
688 {
689 uint64_t de = zp->z_id;
690
691 if (zp->z_zfsvfs->z_version >= ZPL_VERSION_DIRENT_TYPE)
692 de |= IFTODT(mode) << 60;
693 return (de);
694 }
695
696 /*
|