Deleted Added
full compact
zfs_dir.c (303970) zfs_dir.c (321545)
1/*
2 * CDDL HEADER START
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

--- 4 unchanged lines hidden (view full) ---

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 */
1/*
2 * CDDL HEADER START
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

--- 4 unchanged lines hidden (view full) ---

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
21/*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2013, 2015 by Delphix. All rights reserved.
22/*
23 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2013, 2015 by Delphix. All rights reserved.
25 * Copyright 2017 Nexenta Systems, Inc.
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>

--- 26 unchanged lines hidden (view full) ---

58#include <sys/extdirent.h>
59
60/*
61 * zfs_match_find() is used by zfs_dirent_lookup() to peform zap lookups
62 * of names after deciding which is the appropriate lookup interface.
63 */
64static int
65zfs_match_find(zfsvfs_t *zfsvfs, znode_t *dzp, const char *name,
26 */
27
28#include <sys/types.h>
29#include <sys/param.h>
30#include <sys/time.h>
31#include <sys/systm.h>
32#include <sys/sysmacros.h>
33#include <sys/resource.h>

--- 26 unchanged lines hidden (view full) ---

60#include <sys/extdirent.h>
61
62/*
63 * zfs_match_find() is used by zfs_dirent_lookup() to peform zap lookups
64 * of names after deciding which is the appropriate lookup interface.
65 */
66static int
67zfs_match_find(zfsvfs_t *zfsvfs, znode_t *dzp, const char *name,
66 boolean_t exact, uint64_t *zoid)
68 matchtype_t mt, uint64_t *zoid)
67{
68 int error;
69
70 if (zfsvfs->z_norm) {
69{
70 int error;
71
72 if (zfsvfs->z_norm) {
71 matchtype_t mt = exact? MT_EXACT : MT_FIRST;
72
73 /*
74 * In the non-mixed case we only expect there would ever
75 * be one match, but we need to use the normalizing lookup.
76 */
77 error = zap_lookup_norm(zfsvfs->z_os, dzp->z_id, name, 8, 1,
78 zoid, mt, NULL, 0, NULL);
79 } else {

--- 23 unchanged lines hidden (view full) ---

103 * Return value: 0 on success or errno on failure.
104 *
105 * NOTE: Always checks for, and rejects, '.' and '..'.
106 */
107int
108zfs_dirent_lookup(znode_t *dzp, const char *name, znode_t **zpp, int flag)
109{
110 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
73
74 /*
75 * In the non-mixed case we only expect there would ever
76 * be one match, but we need to use the normalizing lookup.
77 */
78 error = zap_lookup_norm(zfsvfs->z_os, dzp->z_id, name, 8, 1,
79 zoid, mt, NULL, 0, NULL);
80 } else {

--- 23 unchanged lines hidden (view full) ---

104 * Return value: 0 on success or errno on failure.
105 *
106 * NOTE: Always checks for, and rejects, '.' and '..'.
107 */
108int
109zfs_dirent_lookup(znode_t *dzp, const char *name, znode_t **zpp, int flag)
110{
111 zfsvfs_t *zfsvfs = dzp->z_zfsvfs;
111 boolean_t exact;
112 matchtype_t mt = 0;
112 uint64_t zoid;
113 vnode_t *vp = NULL;
114 int error = 0;
115
116 ASSERT_VOP_LOCKED(ZTOV(dzp), __func__);
117
118 *zpp = NULL;
119

--- 6 unchanged lines hidden (view full) ---

126 return (SET_ERROR(EEXIST));
127
128 /*
129 * Case sensitivity and normalization preferences are set when
130 * the file system is created. These are stored in the
131 * zfsvfs->z_case and zfsvfs->z_norm fields. These choices
132 * affect how we perform zap lookups.
133 *
113 uint64_t zoid;
114 vnode_t *vp = NULL;
115 int error = 0;
116
117 ASSERT_VOP_LOCKED(ZTOV(dzp), __func__);
118
119 *zpp = NULL;
120

--- 6 unchanged lines hidden (view full) ---

127 return (SET_ERROR(EEXIST));
128
129 /*
130 * Case sensitivity and normalization preferences are set when
131 * the file system is created. These are stored in the
132 * zfsvfs->z_case and zfsvfs->z_norm fields. These choices
133 * affect how we perform zap lookups.
134 *
134 * Decide if exact matches should be requested when performing
135 * a zap lookup on file systems supporting case-insensitive
136 * access.
135 * When matching we may need to normalize & change case according to
136 * FS settings.
137 *
137 *
138 * Note that a normalized match is necessary for a case insensitive
139 * filesystem when the lookup request is not exact because normalization
140 * can fold case independent of normalizing code point sequences.
141 *
142 * See the table above zfs_dropname().
143 */
144 if (zfsvfs->z_norm != 0) {
145 mt = MT_NORMALIZE;
146
147 /*
148 * Determine if the match needs to honor the case specified in
149 * lookup, and if so keep track of that so that during
150 * normalization we don't fold case.
151 */
152 if (zfsvfs->z_case == ZFS_CASE_MIXED) {
153 mt |= MT_MATCH_CASE;
154 }
155 }
156
157 /*
158 * Only look in or update the DNLC if we are looking for the
159 * name on a file system that does not require normalization
160 * or case folding. We can also look there if we happen to be
161 * on a non-normalizing, mixed sensitivity file system IF we
162 * are looking for the exact name.
163 *
138 * NB: we do not need to worry about this flag for ZFS_CASE_SENSITIVE
139 * because in that case MT_EXACT and MT_FIRST should produce exactly
140 * the same result.
141 */
164 * NB: we do not need to worry about this flag for ZFS_CASE_SENSITIVE
165 * because in that case MT_EXACT and MT_FIRST should produce exactly
166 * the same result.
167 */
142 exact = zfsvfs->z_case == ZFS_CASE_MIXED;
143
144 if (dzp->z_unlinked && !(flag & ZXATTR))
145 return (ENOENT);
146 if (flag & ZXATTR) {
147 error = sa_lookup(dzp->z_sa_hdl, SA_ZPL_XATTR(zfsvfs), &zoid,
148 sizeof (zoid));
149 if (error == 0)
150 error = (zoid == 0 ? ENOENT : 0);
151 } else {
168
169 if (dzp->z_unlinked && !(flag & ZXATTR))
170 return (ENOENT);
171 if (flag & ZXATTR) {
172 error = sa_lookup(dzp->z_sa_hdl, SA_ZPL_XATTR(zfsvfs), &zoid,
173 sizeof (zoid));
174 if (error == 0)
175 error = (zoid == 0 ? ENOENT : 0);
176 } else {
152 error = zfs_match_find(zfsvfs, dzp, name, exact, &zoid);
177 error = zfs_match_find(zfsvfs, dzp, name, mt, &zoid);
153 }
154 if (error) {
155 if (error != ENOENT || (flag & ZEXISTS)) {
156 return (error);
157 }
158 } else {
159 if (flag & ZNEW) {
160 return (SET_ERROR(EEXIST));

--- 400 unchanged lines hidden (view full) ---

561 value = zfs_dirent(zp, zp->z_mode);
562 error = zap_add(zp->z_zfsvfs->z_os, dzp->z_id, name,
563 8, 1, &value, tx);
564 VERIFY0(error);
565
566 return (0);
567}
568
178 }
179 if (error) {
180 if (error != ENOENT || (flag & ZEXISTS)) {
181 return (error);
182 }
183 } else {
184 if (flag & ZNEW) {
185 return (SET_ERROR(EEXIST));

--- 400 unchanged lines hidden (view full) ---

586 value = zfs_dirent(zp, zp->z_mode);
587 error = zap_add(zp->z_zfsvfs->z_os, dzp->z_id, name,
588 8, 1, &value, tx);
589 VERIFY0(error);
590
591 return (0);
592}
593
594/*
595 * The match type in the code for this function should conform to:
596 *
597 * ------------------------------------------------------------------------
598 * fs type | z_norm | lookup type | match type
599 * ---------|-------------|-------------|----------------------------------
600 * CS !norm | 0 | 0 | 0 (exact)
601 * CS norm | formX | 0 | MT_NORMALIZE
602 * CI !norm | upper | !ZCIEXACT | MT_NORMALIZE
603 * CI !norm | upper | ZCIEXACT | MT_NORMALIZE | MT_MATCH_CASE
604 * CI norm | upper|formX | !ZCIEXACT | MT_NORMALIZE
605 * CI norm | upper|formX | ZCIEXACT | MT_NORMALIZE | MT_MATCH_CASE
606 * CM !norm | upper | !ZCILOOK | MT_NORMALIZE | MT_MATCH_CASE
607 * CM !norm | upper | ZCILOOK | MT_NORMALIZE
608 * CM norm | upper|formX | !ZCILOOK | MT_NORMALIZE | MT_MATCH_CASE
609 * CM norm | upper|formX | ZCILOOK | MT_NORMALIZE
610 *
611 * Abbreviations:
612 * CS = Case Sensitive, CI = Case Insensitive, CM = Case Mixed
613 * upper = case folding set by fs type on creation (U8_TEXTPREP_TOUPPER)
614 * formX = unicode normalization form set on fs creation
615 */
569static int
570zfs_dropname(znode_t *dzp, const char *name, znode_t *zp, dmu_tx_t *tx,
571 int flag)
572{
573 int error;
574
575 if (zp->z_zfsvfs->z_norm) {
616static int
617zfs_dropname(znode_t *dzp, const char *name, znode_t *zp, dmu_tx_t *tx,
618 int flag)
619{
620 int error;
621
622 if (zp->z_zfsvfs->z_norm) {
576 if (zp->z_zfsvfs->z_case == ZFS_CASE_MIXED)
577 error = zap_remove_norm(zp->z_zfsvfs->z_os,
578 dzp->z_id, name, MT_EXACT, tx);
579 else
580 error = zap_remove_norm(zp->z_zfsvfs->z_os,
581 dzp->z_id, name, MT_FIRST, tx);
623 matchtype_t mt = MT_NORMALIZE;
624
625 if (zp->z_zfsvfs->z_case == ZFS_CASE_MIXED) {
626 mt |= MT_MATCH_CASE;
627 }
628
629 error = zap_remove_norm(zp->z_zfsvfs->z_os, dzp->z_id,
630 name, mt, tx);
582 } else {
631 } else {
583 error = zap_remove(zp->z_zfsvfs->z_os,
584 dzp->z_id, name, tx);
632 error = zap_remove(zp->z_zfsvfs->z_os, dzp->z_id, name, tx);
585 }
586
587 return (error);
588}
589
590/*
591 * Unlink zp from dzp, and mark zp for deletion if this was the last link.
592 * Can fail if zp is a mount point (EBUSY) or a non-empty directory (EEXIST).

--- 284 unchanged lines hidden ---
633 }
634
635 return (error);
636}
637
638/*
639 * Unlink zp from dzp, and mark zp for deletion if this was the last link.
640 * Can fail if zp is a mount point (EBUSY) or a non-empty directory (EEXIST).

--- 284 unchanged lines hidden ---