Deleted Added
full compact
vfs_vnops.c (92069) vfs_vnops.c (92130)
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

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

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)vfs_vnops.c 8.2 (Berkeley) 1/21/94
1/*
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

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

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)vfs_vnops.c 8.2 (Berkeley) 1/21/94
39 * $FreeBSD: head/sys/kern/vfs_vnops.c 92069 2002-03-11 07:53:13Z tanimura $
39 * $FreeBSD: head/sys/kern/vfs_vnops.c 92130 2002-03-12 04:00:11Z jeff $
40 */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/fcntl.h>
45#include <sys/file.h>
46#include <sys/stat.h>
47#include <sys/proc.h>

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

100 struct ucred *cred;
101{
102 struct vnode *vp;
103 struct mount *mp;
104 struct thread *td = ndp->ni_cnd.cn_thread;
105 struct vattr vat;
106 struct vattr *vap = &vat;
107 int mode, fmode, error;
40 */
41
42#include <sys/param.h>
43#include <sys/systm.h>
44#include <sys/fcntl.h>
45#include <sys/file.h>
46#include <sys/stat.h>
47#include <sys/proc.h>

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

100 struct ucred *cred;
101{
102 struct vnode *vp;
103 struct mount *mp;
104 struct thread *td = ndp->ni_cnd.cn_thread;
105 struct vattr vat;
106 struct vattr *vap = &vat;
107 int mode, fmode, error;
108#ifdef LOOKUP_SHARED
109 int exclusive; /* The current intended lock state */
108
110
111 exclusive = 0;
112#endif
113
109restart:
110 fmode = *flagp;
111 if (fmode & O_CREAT) {
112 ndp->ni_cnd.cn_nameiop = CREATE;
113 ndp->ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF;
114 if ((fmode & O_EXCL) == 0 && (fmode & O_NOFOLLOW) == 0)
115 ndp->ni_cnd.cn_flags |= FOLLOW;
116 bwillwrite();

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

138 if (error) {
139 NDFREE(ndp, NDF_ONLY_PNBUF);
140 return (error);
141 }
142 ASSERT_VOP_UNLOCKED(ndp->ni_dvp, "create");
143 ASSERT_VOP_LOCKED(ndp->ni_vp, "create");
144 fmode &= ~O_TRUNC;
145 vp = ndp->ni_vp;
114restart:
115 fmode = *flagp;
116 if (fmode & O_CREAT) {
117 ndp->ni_cnd.cn_nameiop = CREATE;
118 ndp->ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF;
119 if ((fmode & O_EXCL) == 0 && (fmode & O_NOFOLLOW) == 0)
120 ndp->ni_cnd.cn_flags |= FOLLOW;
121 bwillwrite();

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

143 if (error) {
144 NDFREE(ndp, NDF_ONLY_PNBUF);
145 return (error);
146 }
147 ASSERT_VOP_UNLOCKED(ndp->ni_dvp, "create");
148 ASSERT_VOP_LOCKED(ndp->ni_vp, "create");
149 fmode &= ~O_TRUNC;
150 vp = ndp->ni_vp;
151#ifdef LOOKUP_SHARED
152 exclusive = 1;
153#endif
146 } else {
147 if (ndp->ni_dvp == ndp->ni_vp)
148 vrele(ndp->ni_dvp);
149 else
150 vput(ndp->ni_dvp);
151 ndp->ni_dvp = NULL;
152 vp = ndp->ni_vp;
153 if (fmode & O_EXCL) {
154 error = EEXIST;
155 goto bad;
156 }
157 fmode &= ~O_CREAT;
158 }
159 } else {
160 ndp->ni_cnd.cn_nameiop = LOOKUP;
154 } else {
155 if (ndp->ni_dvp == ndp->ni_vp)
156 vrele(ndp->ni_dvp);
157 else
158 vput(ndp->ni_dvp);
159 ndp->ni_dvp = NULL;
160 vp = ndp->ni_vp;
161 if (fmode & O_EXCL) {
162 error = EEXIST;
163 goto bad;
164 }
165 fmode &= ~O_CREAT;
166 }
167 } else {
168 ndp->ni_cnd.cn_nameiop = LOOKUP;
169#ifdef LOOKUP_SHARED
161 ndp->ni_cnd.cn_flags =
170 ndp->ni_cnd.cn_flags =
171 ((fmode & O_NOFOLLOW) ? NOFOLLOW : FOLLOW) |
172 LOCKSHARED | LOCKLEAF;
173#else
174 ndp->ni_cnd.cn_flags =
162 ((fmode & O_NOFOLLOW) ? NOFOLLOW : FOLLOW) | LOCKLEAF;
175 ((fmode & O_NOFOLLOW) ? NOFOLLOW : FOLLOW) | LOCKLEAF;
176#endif
163 if ((error = namei(ndp)) != 0)
164 return (error);
165 vp = ndp->ni_vp;
166 }
167 if (vp->v_type == VLNK) {
168 error = EMLINK;
169 goto bad;
170 }

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

193 }
194 }
195 if ((error = VOP_OPEN(vp, fmode, cred, td)) != 0)
196 goto bad;
197 /*
198 * Make sure that a VM object is created for VMIO support.
199 */
200 if (vn_canvmio(vp) == TRUE) {
177 if ((error = namei(ndp)) != 0)
178 return (error);
179 vp = ndp->ni_vp;
180 }
181 if (vp->v_type == VLNK) {
182 error = EMLINK;
183 goto bad;
184 }

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

207 }
208 }
209 if ((error = VOP_OPEN(vp, fmode, cred, td)) != 0)
210 goto bad;
211 /*
212 * Make sure that a VM object is created for VMIO support.
213 */
214 if (vn_canvmio(vp) == TRUE) {
215#ifdef LOOKUP_SHARED
216 int flock;
217
218 if (!exclusive && vp->v_object == NULL)
219 VOP_LOCK(vp, LK_UPGRADE, td);
220 /*
221 * In cases where the object is marked as dead object_create
222 * will unlock and relock exclusive. It is safe to call in
223 * here with a shared lock because we only examine fields that
224 * the shared lock guarantees will be stable. In the UPGRADE
225 * case it is not likely that anyone has used this vnode yet
226 * so there will be no contention. The logic after this call
227 * restores the requested locking state.
228 */
229#endif
201 if ((error = vfs_object_create(vp, td, cred)) != 0) {
202 VOP_UNLOCK(vp, 0, td);
203 VOP_CLOSE(vp, fmode, cred, td);
204 NDFREE(ndp, NDF_ONLY_PNBUF);
205 vrele(vp);
206 *flagp = fmode;
207 return (error);
208 }
230 if ((error = vfs_object_create(vp, td, cred)) != 0) {
231 VOP_UNLOCK(vp, 0, td);
232 VOP_CLOSE(vp, fmode, cred, td);
233 NDFREE(ndp, NDF_ONLY_PNBUF);
234 vrele(vp);
235 *flagp = fmode;
236 return (error);
237 }
238#ifdef LOOKUP_SHARED
239 flock = VOP_ISLOCKED(vp, td);
240 if (!exclusive && flock == LK_EXCLUSIVE)
241 VOP_LOCK(vp, LK_DOWNGRADE, td);
242#endif
209 }
210
211 if (fmode & FWRITE)
212 vp->v_writecount++;
213 *flagp = fmode;
214 return (0);
215bad:
216 NDFREE(ndp, NDF_ONLY_PNBUF);

--- 794 unchanged lines hidden ---
243 }
244
245 if (fmode & FWRITE)
246 vp->v_writecount++;
247 *flagp = fmode;
248 return (0);
249bad:
250 NDFREE(ndp, NDF_ONLY_PNBUF);

--- 794 unchanged lines hidden ---