]>
Commit | Line | Data |
---|---|---|
ee154f01 BB |
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 | |
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) 2011, Lawrence Livermore National Security, LLC. | |
5475aada | 23 | * Copyright (c) 2015 by Chunwei Chen. All rights reserved. |
ee154f01 BB |
24 | */ |
25 | ||
26 | ||
278bee93 | 27 | #include <sys/zfs_ctldir.h> |
ee154f01 BB |
28 | #include <sys/zfs_vfsops.h> |
29 | #include <sys/zfs_vnops.h> | |
ebe7e575 | 30 | #include <sys/zfs_znode.h> |
24ef51f6 | 31 | #include <sys/dmu_objset.h> |
ee154f01 BB |
32 | #include <sys/vfs.h> |
33 | #include <sys/zpl.h> | |
34 | ||
35 | ||
36 | static struct dentry * | |
8f195a90 | 37 | #ifdef HAVE_LOOKUP_NAMEIDATA |
ee154f01 | 38 | zpl_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd) |
8f195a90 YS |
39 | #else |
40 | zpl_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags) | |
41 | #endif | |
ee154f01 | 42 | { |
81e97e21 | 43 | cred_t *cr = CRED(); |
ee154f01 | 44 | struct inode *ip; |
ee154f01 | 45 | int error; |
40d06e3c | 46 | fstrans_cookie_t cookie; |
c5d02870 RS |
47 | pathname_t *ppn = NULL; |
48 | pathname_t pn; | |
49 | zfs_sb_t *zsb = dentry->d_sb->s_fs_info; | |
ee154f01 | 50 | |
9878a89d | 51 | if (dlen(dentry) > ZFS_MAXNAMELEN) |
d1d7e268 | 52 | return (ERR_PTR(-ENAMETOOLONG)); |
9878a89d | 53 | |
81e97e21 | 54 | crhold(cr); |
40d06e3c | 55 | cookie = spl_fstrans_mark(); |
c5d02870 RS |
56 | |
57 | /* If we are a case insensitive fs, we need the real name */ | |
58 | if (zsb->z_case == ZFS_CASE_INSENSITIVE) { | |
59 | pn.pn_bufsize = ZFS_MAXNAMELEN; | |
60 | pn.pn_buf = kmem_zalloc(ZFS_MAXNAMELEN, KM_SLEEP); | |
61 | ppn = &pn; | |
62 | } | |
63 | ||
64 | error = -zfs_lookup(dir, dname(dentry), &ip, 0, cr, NULL, ppn); | |
40d06e3c | 65 | spl_fstrans_unmark(cookie); |
ee154f01 | 66 | ASSERT3S(error, <=, 0); |
81e97e21 | 67 | crfree(cr); |
ee154f01 | 68 | |
7b3e34ba BB |
69 | spin_lock(&dentry->d_lock); |
70 | dentry->d_time = jiffies; | |
ee930353 BB |
71 | #ifndef HAVE_S_D_OP |
72 | d_set_d_op(dentry, &zpl_dentry_operations); | |
73 | #endif /* HAVE_S_D_OP */ | |
7b3e34ba BB |
74 | spin_unlock(&dentry->d_lock); |
75 | ||
ee154f01 | 76 | if (error) { |
c5d02870 RS |
77 | if (ppn) |
78 | kmem_free(pn.pn_buf, ZFS_MAXNAMELEN); | |
ee154f01 | 79 | if (error == -ENOENT) |
d1d7e268 | 80 | return (d_splice_alias(NULL, dentry)); |
ee154f01 | 81 | else |
d1d7e268 | 82 | return (ERR_PTR(error)); |
ee154f01 BB |
83 | } |
84 | ||
c5d02870 RS |
85 | /* |
86 | * If we are case insensitive, call the correct function | |
87 | * to install the name. | |
88 | */ | |
89 | if (ppn) { | |
90 | struct dentry *new_dentry; | |
91 | struct qstr ci_name; | |
92 | ||
93 | ci_name.name = pn.pn_buf; | |
94 | ci_name.len = strlen(pn.pn_buf); | |
95 | new_dentry = d_add_ci(dentry, ip, &ci_name); | |
96 | kmem_free(pn.pn_buf, ZFS_MAXNAMELEN); | |
97 | return (new_dentry); | |
98 | } else { | |
99 | return (d_splice_alias(ip, dentry)); | |
100 | } | |
ee154f01 BB |
101 | } |
102 | ||
ebe7e575 | 103 | void |
7b3e34ba | 104 | zpl_vap_init(vattr_t *vap, struct inode *dir, zpl_umode_t mode, cred_t *cr) |
9fd91dae BB |
105 | { |
106 | vap->va_mask = ATTR_MODE; | |
107 | vap->va_mode = mode; | |
9fd91dae BB |
108 | vap->va_uid = crgetfsuid(cr); |
109 | ||
110 | if (dir && dir->i_mode & S_ISGID) { | |
570d6edf | 111 | vap->va_gid = KGID_TO_SGID(dir->i_gid); |
9fd91dae BB |
112 | if (S_ISDIR(mode)) |
113 | vap->va_mode |= S_ISGID; | |
114 | } else { | |
115 | vap->va_gid = crgetfsgid(cr); | |
116 | } | |
117 | } | |
118 | ||
ee154f01 | 119 | static int |
558ef6d0 | 120 | #ifdef HAVE_CREATE_NAMEIDATA |
b39d3b9f | 121 | zpl_create(struct inode *dir, struct dentry *dentry, zpl_umode_t mode, |
ee154f01 | 122 | struct nameidata *nd) |
558ef6d0 YS |
123 | #else |
124 | zpl_create(struct inode *dir, struct dentry *dentry, zpl_umode_t mode, | |
125 | bool flag) | |
126 | #endif | |
ee154f01 | 127 | { |
81e97e21 | 128 | cred_t *cr = CRED(); |
ee154f01 BB |
129 | struct inode *ip; |
130 | vattr_t *vap; | |
131 | int error; | |
40d06e3c | 132 | fstrans_cookie_t cookie; |
ee154f01 | 133 | |
81e97e21 | 134 | crhold(cr); |
d1d7e268 | 135 | vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP); |
7b3e34ba | 136 | zpl_vap_init(vap, dir, mode, cr); |
ee154f01 | 137 | |
40d06e3c | 138 | cookie = spl_fstrans_mark(); |
e89260a1 BB |
139 | error = -zfs_create(dir, dname(dentry), vap, 0, mode, &ip, cr, 0, NULL); |
140 | if (error == 0) { | |
7b3e34ba | 141 | d_instantiate(dentry, ip); |
214806c7 DL |
142 | |
143 | error = zpl_xattr_security_init(ip, dir, &dentry->d_name); | |
144 | if (error == 0) | |
145 | error = zpl_init_acl(ip, dir); | |
146 | ||
147 | if (error) | |
148 | (void) zfs_remove(dir, dname(dentry), cr); | |
e89260a1 BB |
149 | } |
150 | ||
a438ff0e | 151 | spl_fstrans_unmark(cookie); |
d1d7e268 | 152 | kmem_free(vap, sizeof (vattr_t)); |
81e97e21 | 153 | crfree(cr); |
ee154f01 BB |
154 | ASSERT3S(error, <=, 0); |
155 | ||
156 | return (error); | |
157 | } | |
158 | ||
159 | static int | |
b39d3b9f BB |
160 | zpl_mknod(struct inode *dir, struct dentry *dentry, zpl_umode_t mode, |
161 | dev_t rdev) | |
ee154f01 | 162 | { |
81e97e21 | 163 | cred_t *cr = CRED(); |
ee154f01 BB |
164 | struct inode *ip; |
165 | vattr_t *vap; | |
166 | int error; | |
40d06e3c | 167 | fstrans_cookie_t cookie; |
ee154f01 | 168 | |
aa6d8c10 NB |
169 | /* |
170 | * We currently expect Linux to supply rdev=0 for all sockets | |
171 | * and fifos, but we want to know if this behavior ever changes. | |
172 | */ | |
173 | if (S_ISSOCK(mode) || S_ISFIFO(mode)) | |
174 | ASSERT(rdev == 0); | |
175 | ||
81e97e21 | 176 | crhold(cr); |
d1d7e268 | 177 | vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP); |
7b3e34ba | 178 | zpl_vap_init(vap, dir, mode, cr); |
ee154f01 | 179 | vap->va_rdev = rdev; |
ee154f01 | 180 | |
40d06e3c | 181 | cookie = spl_fstrans_mark(); |
7b3e34ba | 182 | error = -zfs_create(dir, dname(dentry), vap, 0, mode, &ip, cr, 0, NULL); |
023699cd | 183 | if (error == 0) { |
7b3e34ba | 184 | d_instantiate(dentry, ip); |
214806c7 DL |
185 | |
186 | error = zpl_xattr_security_init(ip, dir, &dentry->d_name); | |
187 | if (error == 0) | |
188 | error = zpl_init_acl(ip, dir); | |
189 | ||
190 | if (error) | |
191 | (void) zfs_remove(dir, dname(dentry), cr); | |
023699cd | 192 | } |
7b3e34ba | 193 | |
a438ff0e | 194 | spl_fstrans_unmark(cookie); |
d1d7e268 | 195 | kmem_free(vap, sizeof (vattr_t)); |
81e97e21 | 196 | crfree(cr); |
ee154f01 BB |
197 | ASSERT3S(error, <=, 0); |
198 | ||
34d5a5fd | 199 | return (error); |
ee154f01 BB |
200 | } |
201 | ||
202 | static int | |
203 | zpl_unlink(struct inode *dir, struct dentry *dentry) | |
204 | { | |
81e97e21 | 205 | cred_t *cr = CRED(); |
ee154f01 | 206 | int error; |
40d06e3c | 207 | fstrans_cookie_t cookie; |
ee154f01 | 208 | |
81e97e21 | 209 | crhold(cr); |
40d06e3c | 210 | cookie = spl_fstrans_mark(); |
ee154f01 | 211 | error = -zfs_remove(dir, dname(dentry), cr); |
40d06e3c | 212 | spl_fstrans_unmark(cookie); |
81e97e21 | 213 | crfree(cr); |
ee154f01 BB |
214 | ASSERT3S(error, <=, 0); |
215 | ||
216 | return (error); | |
217 | } | |
218 | ||
219 | static int | |
b39d3b9f | 220 | zpl_mkdir(struct inode *dir, struct dentry *dentry, zpl_umode_t mode) |
ee154f01 | 221 | { |
81e97e21 | 222 | cred_t *cr = CRED(); |
ee154f01 BB |
223 | vattr_t *vap; |
224 | struct inode *ip; | |
225 | int error; | |
40d06e3c | 226 | fstrans_cookie_t cookie; |
ee154f01 | 227 | |
81e97e21 | 228 | crhold(cr); |
d1d7e268 | 229 | vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP); |
7b3e34ba | 230 | zpl_vap_init(vap, dir, mode | S_IFDIR, cr); |
ee154f01 | 231 | |
40d06e3c | 232 | cookie = spl_fstrans_mark(); |
ee154f01 | 233 | error = -zfs_mkdir(dir, dname(dentry), vap, &ip, cr, 0, NULL); |
023699cd | 234 | if (error == 0) { |
7b3e34ba | 235 | d_instantiate(dentry, ip); |
214806c7 DL |
236 | |
237 | error = zpl_xattr_security_init(ip, dir, &dentry->d_name); | |
238 | if (error == 0) | |
239 | error = zpl_init_acl(ip, dir); | |
240 | ||
241 | if (error) | |
242 | (void) zfs_rmdir(dir, dname(dentry), NULL, cr, 0); | |
023699cd | 243 | } |
7b3e34ba | 244 | |
a438ff0e | 245 | spl_fstrans_unmark(cookie); |
d1d7e268 | 246 | kmem_free(vap, sizeof (vattr_t)); |
81e97e21 | 247 | crfree(cr); |
ee154f01 BB |
248 | ASSERT3S(error, <=, 0); |
249 | ||
250 | return (error); | |
251 | } | |
252 | ||
253 | static int | |
254 | zpl_rmdir(struct inode * dir, struct dentry *dentry) | |
255 | { | |
81e97e21 | 256 | cred_t *cr = CRED(); |
ee154f01 | 257 | int error; |
40d06e3c | 258 | fstrans_cookie_t cookie; |
ee154f01 | 259 | |
81e97e21 | 260 | crhold(cr); |
40d06e3c | 261 | cookie = spl_fstrans_mark(); |
ee154f01 | 262 | error = -zfs_rmdir(dir, dname(dentry), NULL, cr, 0); |
40d06e3c | 263 | spl_fstrans_unmark(cookie); |
81e97e21 | 264 | crfree(cr); |
ee154f01 BB |
265 | ASSERT3S(error, <=, 0); |
266 | ||
267 | return (error); | |
268 | } | |
269 | ||
270 | static int | |
271 | zpl_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat) | |
272 | { | |
ee154f01 | 273 | int error; |
40d06e3c | 274 | fstrans_cookie_t cookie; |
ee154f01 | 275 | |
40d06e3c | 276 | cookie = spl_fstrans_mark(); |
057e8eee | 277 | error = -zfs_getattr_fast(dentry->d_inode, stat); |
40d06e3c | 278 | spl_fstrans_unmark(cookie); |
ee154f01 BB |
279 | ASSERT3S(error, <=, 0); |
280 | ||
281 | return (error); | |
282 | } | |
283 | ||
284 | static int | |
5484965a | 285 | zpl_setattr(struct dentry *dentry, struct iattr *ia) |
ee154f01 | 286 | { |
023699cd | 287 | struct inode *ip = dentry->d_inode; |
81e97e21 | 288 | cred_t *cr = CRED(); |
5484965a | 289 | vattr_t *vap; |
ee154f01 | 290 | int error; |
40d06e3c | 291 | fstrans_cookie_t cookie; |
ee154f01 | 292 | |
023699cd | 293 | error = inode_change_ok(ip, ia); |
ee154f01 BB |
294 | if (error) |
295 | return (error); | |
296 | ||
81e97e21 | 297 | crhold(cr); |
d1d7e268 | 298 | vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP); |
5484965a BB |
299 | vap->va_mask = ia->ia_valid & ATTR_IATTR_MASK; |
300 | vap->va_mode = ia->ia_mode; | |
570d6edf RY |
301 | vap->va_uid = KUID_TO_SUID(ia->ia_uid); |
302 | vap->va_gid = KGID_TO_SGID(ia->ia_gid); | |
5484965a BB |
303 | vap->va_size = ia->ia_size; |
304 | vap->va_atime = ia->ia_atime; | |
305 | vap->va_mtime = ia->ia_mtime; | |
306 | vap->va_ctime = ia->ia_ctime; | |
307 | ||
40d06e3c | 308 | cookie = spl_fstrans_mark(); |
023699cd MM |
309 | error = -zfs_setattr(ip, vap, 0, cr); |
310 | if (!error && (ia->ia_valid & ATTR_MODE)) | |
311 | error = zpl_chmod_acl(ip); | |
5484965a | 312 | |
a438ff0e | 313 | spl_fstrans_unmark(cookie); |
d1d7e268 | 314 | kmem_free(vap, sizeof (vattr_t)); |
81e97e21 | 315 | crfree(cr); |
ee154f01 BB |
316 | ASSERT3S(error, <=, 0); |
317 | ||
5484965a | 318 | return (error); |
ee154f01 BB |
319 | } |
320 | ||
321 | static int | |
322 | zpl_rename(struct inode *sdip, struct dentry *sdentry, | |
323 | struct inode *tdip, struct dentry *tdentry) | |
324 | { | |
81e97e21 | 325 | cred_t *cr = CRED(); |
ee154f01 | 326 | int error; |
40d06e3c | 327 | fstrans_cookie_t cookie; |
ee154f01 | 328 | |
81e97e21 | 329 | crhold(cr); |
40d06e3c | 330 | cookie = spl_fstrans_mark(); |
ee154f01 | 331 | error = -zfs_rename(sdip, dname(sdentry), tdip, dname(tdentry), cr, 0); |
40d06e3c | 332 | spl_fstrans_unmark(cookie); |
81e97e21 | 333 | crfree(cr); |
ee154f01 BB |
334 | ASSERT3S(error, <=, 0); |
335 | ||
336 | return (error); | |
337 | } | |
338 | ||
339 | static int | |
340 | zpl_symlink(struct inode *dir, struct dentry *dentry, const char *name) | |
341 | { | |
81e97e21 | 342 | cred_t *cr = CRED(); |
ee154f01 BB |
343 | vattr_t *vap; |
344 | struct inode *ip; | |
345 | int error; | |
40d06e3c | 346 | fstrans_cookie_t cookie; |
ee154f01 | 347 | |
81e97e21 | 348 | crhold(cr); |
d1d7e268 | 349 | vap = kmem_zalloc(sizeof (vattr_t), KM_SLEEP); |
7b3e34ba | 350 | zpl_vap_init(vap, dir, S_IFLNK | S_IRWXUGO, cr); |
ee154f01 | 351 | |
40d06e3c | 352 | cookie = spl_fstrans_mark(); |
ee154f01 | 353 | error = -zfs_symlink(dir, dname(dentry), vap, (char *)name, &ip, cr, 0); |
227bc969 | 354 | if (error == 0) { |
7b3e34ba | 355 | d_instantiate(dentry, ip); |
214806c7 DL |
356 | |
357 | error = zpl_xattr_security_init(ip, dir, &dentry->d_name); | |
358 | if (error) | |
359 | (void) zfs_remove(dir, dname(dentry), cr); | |
227bc969 | 360 | } |
7b3e34ba | 361 | |
a438ff0e | 362 | spl_fstrans_unmark(cookie); |
d1d7e268 | 363 | kmem_free(vap, sizeof (vattr_t)); |
81e97e21 | 364 | crfree(cr); |
ee154f01 BB |
365 | ASSERT3S(error, <=, 0); |
366 | ||
367 | return (error); | |
368 | } | |
369 | ||
bd29109f | 370 | #ifdef HAVE_FOLLOW_LINK_NAMEIDATA |
ee154f01 BB |
371 | static void * |
372 | zpl_follow_link(struct dentry *dentry, struct nameidata *nd) | |
bd29109f BB |
373 | #else |
374 | const char * | |
375 | zpl_follow_link(struct dentry *dentry, void **symlink_cookie) | |
376 | #endif | |
ee154f01 | 377 | { |
81e97e21 | 378 | cred_t *cr = CRED(); |
8b4f9a2d BB |
379 | struct inode *ip = dentry->d_inode; |
380 | struct iovec iov; | |
381 | uio_t uio; | |
382 | char *link; | |
8b4f9a2d | 383 | int error; |
40d06e3c | 384 | fstrans_cookie_t cookie; |
8b4f9a2d | 385 | |
81e97e21 | 386 | crhold(cr); |
8b4f9a2d BB |
387 | |
388 | iov.iov_len = MAXPATHLEN; | |
389 | iov.iov_base = link = kmem_zalloc(MAXPATHLEN, KM_SLEEP); | |
390 | ||
391 | uio.uio_iov = &iov; | |
392 | uio.uio_iovcnt = 1; | |
5475aada | 393 | uio.uio_skip = 0; |
8b4f9a2d BB |
394 | uio.uio_resid = (MAXPATHLEN - 1); |
395 | uio.uio_segflg = UIO_SYSSPACE; | |
396 | ||
40d06e3c | 397 | cookie = spl_fstrans_mark(); |
50950001 | 398 | error = -zfs_readlink(ip, &uio, cr); |
40d06e3c | 399 | spl_fstrans_unmark(cookie); |
bd29109f BB |
400 | |
401 | if (error) | |
8b4f9a2d | 402 | kmem_free(link, MAXPATHLEN); |
bd29109f BB |
403 | |
404 | crfree(cr); | |
405 | ||
406 | #ifdef HAVE_FOLLOW_LINK_NAMEIDATA | |
407 | if (error) | |
8b4f9a2d | 408 | nd_set_link(nd, ERR_PTR(error)); |
bd29109f | 409 | else |
8b4f9a2d | 410 | nd_set_link(nd, link); |
8b4f9a2d | 411 | |
8b4f9a2d | 412 | return (NULL); |
bd29109f BB |
413 | #else |
414 | if (error) | |
415 | return (ERR_PTR(error)); | |
416 | else | |
417 | return (*symlink_cookie = link); | |
418 | #endif | |
ee154f01 BB |
419 | } |
420 | ||
bd29109f | 421 | #ifdef HAVE_PUT_LINK_NAMEIDATA |
ee154f01 BB |
422 | static void |
423 | zpl_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr) | |
424 | { | |
0a6b03d3 | 425 | const char *link = nd_get_link(nd); |
ee154f01 | 426 | |
ee154f01 | 427 | if (!IS_ERR(link)) |
8b4f9a2d | 428 | kmem_free(link, MAXPATHLEN); |
ee154f01 | 429 | } |
bd29109f BB |
430 | #else |
431 | static void | |
432 | zpl_put_link(struct inode *unused, void *symlink_cookie) | |
433 | { | |
434 | kmem_free(symlink_cookie, MAXPATHLEN); | |
435 | } | |
436 | #endif | |
ee154f01 BB |
437 | |
438 | static int | |
439 | zpl_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) | |
440 | { | |
81e97e21 | 441 | cred_t *cr = CRED(); |
ee154f01 | 442 | struct inode *ip = old_dentry->d_inode; |
ee154f01 | 443 | int error; |
40d06e3c | 444 | fstrans_cookie_t cookie; |
ee154f01 BB |
445 | |
446 | if (ip->i_nlink >= ZFS_LINK_MAX) | |
d1d7e268 | 447 | return (-EMLINK); |
ee154f01 | 448 | |
81e97e21 | 449 | crhold(cr); |
ee154f01 BB |
450 | ip->i_ctime = CURRENT_TIME_SEC; |
451 | igrab(ip); /* Use ihold() if available */ | |
452 | ||
40d06e3c | 453 | cookie = spl_fstrans_mark(); |
ee154f01 BB |
454 | error = -zfs_link(dir, ip, dname(dentry), cr); |
455 | if (error) { | |
456 | iput(ip); | |
457 | goto out; | |
458 | } | |
459 | ||
460 | d_instantiate(dentry, ip); | |
461 | out: | |
a438ff0e | 462 | spl_fstrans_unmark(cookie); |
81e97e21 | 463 | crfree(cr); |
ee154f01 BB |
464 | ASSERT3S(error, <=, 0); |
465 | ||
466 | return (error); | |
467 | } | |
468 | ||
ea1fdf46 | 469 | #ifdef HAVE_INODE_TRUNCATE_RANGE |
5cb63a57 | 470 | static void |
d1d7e268 | 471 | zpl_truncate_range(struct inode *ip, loff_t start, loff_t end) |
5cb63a57 ED |
472 | { |
473 | cred_t *cr = CRED(); | |
474 | flock64_t bf; | |
40d06e3c | 475 | fstrans_cookie_t cookie; |
5cb63a57 ED |
476 | |
477 | ASSERT3S(start, <=, end); | |
478 | ||
479 | /* | |
480 | * zfs_freesp() will interpret (len == 0) as meaning "truncate until | |
481 | * the end of the file". We don't want that. | |
482 | */ | |
483 | if (start == end) | |
484 | return; | |
485 | ||
486 | crhold(cr); | |
487 | ||
488 | bf.l_type = F_WRLCK; | |
489 | bf.l_whence = 0; | |
490 | bf.l_start = start; | |
491 | bf.l_len = end - start; | |
492 | bf.l_pid = 0; | |
40d06e3c | 493 | cookie = spl_fstrans_mark(); |
5cb63a57 | 494 | zfs_space(ip, F_FREESP, &bf, FWRITE, start, cr); |
40d06e3c | 495 | spl_fstrans_unmark(cookie); |
5cb63a57 ED |
496 | |
497 | crfree(cr); | |
498 | } | |
ea1fdf46 | 499 | #endif /* HAVE_INODE_TRUNCATE_RANGE */ |
5cb63a57 | 500 | |
cb2d1901 ED |
501 | #ifdef HAVE_INODE_FALLOCATE |
502 | static long | |
503 | zpl_fallocate(struct inode *ip, int mode, loff_t offset, loff_t len) | |
504 | { | |
d1d7e268 | 505 | return (zpl_fallocate_common(ip, mode, offset, len)); |
cb2d1901 ED |
506 | } |
507 | #endif /* HAVE_INODE_FALLOCATE */ | |
508 | ||
7b3e34ba BB |
509 | static int |
510 | #ifdef HAVE_D_REVALIDATE_NAMEIDATA | |
511 | zpl_revalidate(struct dentry *dentry, struct nameidata *nd) | |
512 | { | |
09a661e9 | 513 | unsigned int flags = (nd ? nd->flags : 0); |
7b3e34ba BB |
514 | #else |
515 | zpl_revalidate(struct dentry *dentry, unsigned int flags) | |
516 | { | |
517 | #endif /* HAVE_D_REVALIDATE_NAMEIDATA */ | |
518 | zfs_sb_t *zsb = dentry->d_sb->s_fs_info; | |
519 | int error; | |
520 | ||
521 | if (flags & LOOKUP_RCU) | |
522 | return (-ECHILD); | |
523 | ||
278bee93 BB |
524 | /* |
525 | * Automounted snapshots rely on periodic dentry revalidation | |
526 | * to defer snapshots from being automatically unmounted. | |
527 | */ | |
528 | if (zsb->z_issnap) { | |
529 | if (time_after(jiffies, zsb->z_snap_defer_time + | |
530 | MAX(zfs_expire_snapshot * HZ / 2, HZ))) { | |
531 | zsb->z_snap_defer_time = jiffies; | |
24ef51f6 | 532 | zfsctl_snapshot_unmount_delay(zsb->z_os->os_spa, |
278bee93 BB |
533 | dmu_objset_id(zsb->z_os), zfs_expire_snapshot); |
534 | } | |
535 | } | |
536 | ||
7b3e34ba BB |
537 | /* |
538 | * After a rollback negative dentries created before the rollback | |
539 | * time must be invalidated. Otherwise they can obscure files which | |
540 | * are only present in the rolled back dataset. | |
541 | */ | |
542 | if (dentry->d_inode == NULL) { | |
543 | spin_lock(&dentry->d_lock); | |
544 | error = time_before(dentry->d_time, zsb->z_rollback_time); | |
545 | spin_unlock(&dentry->d_lock); | |
546 | ||
547 | if (error) | |
548 | return (0); | |
549 | } | |
550 | ||
551 | /* | |
552 | * The dentry may reference a stale inode if a mounted file system | |
553 | * was rolled back to a point in time where the object didn't exist. | |
554 | */ | |
555 | if (dentry->d_inode && ITOZ(dentry->d_inode)->z_is_stale) | |
556 | return (0); | |
557 | ||
558 | return (1); | |
559 | } | |
cb2d1901 | 560 | |
ee154f01 | 561 | const struct inode_operations zpl_inode_operations = { |
ee154f01 BB |
562 | .create = zpl_create, |
563 | .link = zpl_link, | |
564 | .unlink = zpl_unlink, | |
565 | .symlink = zpl_symlink, | |
566 | .mkdir = zpl_mkdir, | |
567 | .rmdir = zpl_rmdir, | |
568 | .mknod = zpl_mknod, | |
569 | .rename = zpl_rename, | |
570 | .setattr = zpl_setattr, | |
571 | .getattr = zpl_getattr, | |
572 | .setxattr = generic_setxattr, | |
573 | .getxattr = generic_getxattr, | |
574 | .removexattr = generic_removexattr, | |
575 | .listxattr = zpl_xattr_list, | |
ea1fdf46 | 576 | #ifdef HAVE_INODE_TRUNCATE_RANGE |
5cb63a57 | 577 | .truncate_range = zpl_truncate_range, |
ea1fdf46 | 578 | #endif /* HAVE_INODE_TRUNCATE_RANGE */ |
cb2d1901 ED |
579 | #ifdef HAVE_INODE_FALLOCATE |
580 | .fallocate = zpl_fallocate, | |
581 | #endif /* HAVE_INODE_FALLOCATE */ | |
b695c34e | 582 | #if defined(CONFIG_FS_POSIX_ACL) |
023699cd MM |
583 | #if defined(HAVE_GET_ACL) |
584 | .get_acl = zpl_get_acl, | |
585 | #elif defined(HAVE_CHECK_ACL) | |
586 | .check_acl = zpl_check_acl, | |
587 | #elif defined(HAVE_PERMISSION) | |
588 | .permission = zpl_permission, | |
589 | #endif /* HAVE_GET_ACL | HAVE_CHECK_ACL | HAVE_PERMISSION */ | |
b695c34e | 590 | #endif /* CONFIG_FS_POSIX_ACL */ |
ee154f01 BB |
591 | }; |
592 | ||
593 | const struct inode_operations zpl_dir_inode_operations = { | |
ee154f01 BB |
594 | .create = zpl_create, |
595 | .lookup = zpl_lookup, | |
596 | .link = zpl_link, | |
597 | .unlink = zpl_unlink, | |
598 | .symlink = zpl_symlink, | |
599 | .mkdir = zpl_mkdir, | |
600 | .rmdir = zpl_rmdir, | |
601 | .mknod = zpl_mknod, | |
602 | .rename = zpl_rename, | |
603 | .setattr = zpl_setattr, | |
a6695d83 BB |
604 | .getattr = zpl_getattr, |
605 | .setxattr = generic_setxattr, | |
606 | .getxattr = generic_getxattr, | |
607 | .removexattr = generic_removexattr, | |
608 | .listxattr = zpl_xattr_list, | |
b695c34e | 609 | #if defined(CONFIG_FS_POSIX_ACL) |
023699cd MM |
610 | #if defined(HAVE_GET_ACL) |
611 | .get_acl = zpl_get_acl, | |
612 | #elif defined(HAVE_CHECK_ACL) | |
613 | .check_acl = zpl_check_acl, | |
614 | #elif defined(HAVE_PERMISSION) | |
615 | .permission = zpl_permission, | |
616 | #endif /* HAVE_GET_ACL | HAVE_CHECK_ACL | HAVE_PERMISSION */ | |
b695c34e | 617 | #endif /* CONFIG_FS_POSIX_ACL */ |
ee154f01 BB |
618 | }; |
619 | ||
620 | const struct inode_operations zpl_symlink_inode_operations = { | |
ee154f01 BB |
621 | .readlink = generic_readlink, |
622 | .follow_link = zpl_follow_link, | |
623 | .put_link = zpl_put_link, | |
6f2255ba BB |
624 | .setattr = zpl_setattr, |
625 | .getattr = zpl_getattr, | |
f31b3ebe BB |
626 | .setxattr = generic_setxattr, |
627 | .getxattr = generic_getxattr, | |
628 | .removexattr = generic_removexattr, | |
629 | .listxattr = zpl_xattr_list, | |
ee154f01 BB |
630 | }; |
631 | ||
632 | const struct inode_operations zpl_special_inode_operations = { | |
a6695d83 BB |
633 | .setattr = zpl_setattr, |
634 | .getattr = zpl_getattr, | |
635 | .setxattr = generic_setxattr, | |
636 | .getxattr = generic_getxattr, | |
637 | .removexattr = generic_removexattr, | |
638 | .listxattr = zpl_xattr_list, | |
b695c34e | 639 | #if defined(CONFIG_FS_POSIX_ACL) |
023699cd MM |
640 | #if defined(HAVE_GET_ACL) |
641 | .get_acl = zpl_get_acl, | |
642 | #elif defined(HAVE_CHECK_ACL) | |
643 | .check_acl = zpl_check_acl, | |
644 | #elif defined(HAVE_PERMISSION) | |
645 | .permission = zpl_permission, | |
646 | #endif /* HAVE_GET_ACL | HAVE_CHECK_ACL | HAVE_PERMISSION */ | |
b695c34e | 647 | #endif /* CONFIG_FS_POSIX_ACL */ |
ee154f01 | 648 | }; |
7b3e34ba BB |
649 | |
650 | dentry_operations_t zpl_dentry_operations = { | |
651 | .d_revalidate = zpl_revalidate, | |
652 | }; |