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.
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.
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]
22 * Copyright (c) 2011, Lawrence Livermore National Security, LLC.
26 #include <sys/zfs_vfsops.h>
27 #include <sys/zfs_vnops.h>
32 static struct dentry
*
33 zpl_lookup(struct inode
*dir
, struct dentry
*dentry
, struct nameidata
*nd
)
40 error
= -zfs_lookup(dir
, dname(dentry
), &ip
, 0, cr
, NULL
, NULL
);
41 ASSERT3S(error
, <=, 0);
46 return d_splice_alias(NULL
, dentry
);
48 return ERR_PTR(error
);
51 return d_splice_alias(ip
, dentry
);
55 zpl_create(struct inode
*dir
, struct dentry
*dentry
, int mode
,
64 vap
= kmem_zalloc(sizeof(vattr_t
), KM_SLEEP
);
66 vap
->va_mask
= ATTR_MODE
;
67 vap
->va_uid
= crgetfsuid(cr
);
68 vap
->va_gid
= crgetfsgid(cr
);
69 vap
->va_dentry
= dentry
;
71 error
= -zfs_create(dir
, (char *)dentry
->d_name
.name
,
72 vap
, 0, mode
, &ip
, cr
, 0, NULL
);
73 kmem_free(vap
, sizeof(vattr_t
));
75 ASSERT3S(error
, <=, 0);
81 zpl_mknod(struct inode
*dir
, struct dentry
*dentry
, int mode
, dev_t rdev
)
89 * We currently expect Linux to supply rdev=0 for all sockets
90 * and fifos, but we want to know if this behavior ever changes.
92 if (S_ISSOCK(mode
) || S_ISFIFO(mode
))
96 vap
= kmem_zalloc(sizeof(vattr_t
), KM_SLEEP
);
98 vap
->va_mask
= ATTR_MODE
;
100 vap
->va_uid
= crgetfsuid(cr
);
101 vap
->va_gid
= crgetfsgid(cr
);
102 vap
->va_dentry
= dentry
;
104 error
= -zfs_create(dir
, (char *)dentry
->d_name
.name
,
105 vap
, 0, mode
, &ip
, cr
, 0, NULL
);
106 kmem_free(vap
, sizeof(vattr_t
));
108 ASSERT3S(error
, <=, 0);
114 zpl_unlink(struct inode
*dir
, struct dentry
*dentry
)
120 error
= -zfs_remove(dir
, dname(dentry
), cr
);
122 ASSERT3S(error
, <=, 0);
128 zpl_mkdir(struct inode
*dir
, struct dentry
*dentry
, int mode
)
136 vap
= kmem_zalloc(sizeof(vattr_t
), KM_SLEEP
);
137 vap
->va_mode
= S_IFDIR
| mode
;
138 vap
->va_mask
= ATTR_MODE
;
139 vap
->va_uid
= crgetfsuid(cr
);
140 vap
->va_gid
= crgetfsgid(cr
);
141 vap
->va_dentry
= dentry
;
143 error
= -zfs_mkdir(dir
, dname(dentry
), vap
, &ip
, cr
, 0, NULL
);
144 kmem_free(vap
, sizeof(vattr_t
));
146 ASSERT3S(error
, <=, 0);
152 zpl_rmdir(struct inode
* dir
, struct dentry
*dentry
)
158 error
= -zfs_rmdir(dir
, dname(dentry
), NULL
, cr
, 0);
160 ASSERT3S(error
, <=, 0);
166 zpl_getattr(struct vfsmount
*mnt
, struct dentry
*dentry
, struct kstat
*stat
)
173 ip
= dentry
->d_inode
;
175 vap
= kmem_zalloc(sizeof(vattr_t
), KM_SLEEP
);
177 error
= -zfs_getattr(ip
, vap
, 0, cr
);
181 stat
->ino
= ip
->i_ino
;
182 stat
->dev
= ip
->i_sb
->s_dev
;
183 stat
->mode
= vap
->va_mode
;
184 stat
->nlink
= vap
->va_nlink
;
185 stat
->uid
= vap
->va_uid
;
186 stat
->gid
= vap
->va_gid
;
187 stat
->rdev
= vap
->va_rdev
;
188 stat
->size
= vap
->va_size
;
189 stat
->atime
= vap
->va_atime
;
190 stat
->mtime
= vap
->va_mtime
;
191 stat
->ctime
= vap
->va_ctime
;
192 stat
->blksize
= vap
->va_blksize
;
193 stat
->blocks
= vap
->va_nblocks
;
195 kmem_free(vap
, sizeof(vattr_t
));
197 ASSERT3S(error
, <=, 0);
203 zpl_setattr(struct dentry
*dentry
, struct iattr
*ia
)
209 error
= inode_change_ok(dentry
->d_inode
, ia
);
214 vap
= kmem_zalloc(sizeof(vattr_t
), KM_SLEEP
);
215 vap
->va_mask
= ia
->ia_valid
& ATTR_IATTR_MASK
;
216 vap
->va_mode
= ia
->ia_mode
;
217 vap
->va_uid
= ia
->ia_uid
;
218 vap
->va_gid
= ia
->ia_gid
;
219 vap
->va_size
= ia
->ia_size
;
220 vap
->va_atime
= ia
->ia_atime
;
221 vap
->va_mtime
= ia
->ia_mtime
;
222 vap
->va_ctime
= ia
->ia_ctime
;
224 error
= -zfs_setattr(dentry
->d_inode
, vap
, 0, cr
);
226 kmem_free(vap
, sizeof(vattr_t
));
228 ASSERT3S(error
, <=, 0);
234 zpl_rename(struct inode
*sdip
, struct dentry
*sdentry
,
235 struct inode
*tdip
, struct dentry
*tdentry
)
241 error
= -zfs_rename(sdip
, dname(sdentry
), tdip
, dname(tdentry
), cr
, 0);
243 ASSERT3S(error
, <=, 0);
249 zpl_symlink(struct inode
*dir
, struct dentry
*dentry
, const char *name
)
257 vap
= kmem_zalloc(sizeof(vattr_t
), KM_SLEEP
);
258 vap
->va_mode
= S_IFLNK
| S_IRWXUGO
;
259 vap
->va_mask
= ATTR_MODE
;
260 vap
->va_uid
= crgetfsuid(cr
);
261 vap
->va_gid
= crgetfsgid(cr
);
262 vap
->va_dentry
= dentry
;
264 error
= -zfs_symlink(dir
, dname(dentry
), vap
, (char *)name
, &ip
, cr
, 0);
265 kmem_free(vap
, sizeof(vattr_t
));
267 ASSERT3S(error
, <=, 0);
273 zpl_follow_link(struct dentry
*dentry
, struct nameidata
*nd
)
276 struct inode
*ip
= dentry
->d_inode
;
284 iov
.iov_len
= MAXPATHLEN
;
285 iov
.iov_base
= link
= kmem_zalloc(MAXPATHLEN
, KM_SLEEP
);
289 uio
.uio_resid
= (MAXPATHLEN
- 1);
290 uio
.uio_segflg
= UIO_SYSSPACE
;
292 error
= -zfs_readlink(ip
, &uio
, cr
);
294 kmem_free(link
, MAXPATHLEN
);
295 nd_set_link(nd
, ERR_PTR(error
));
297 nd_set_link(nd
, link
);
305 zpl_put_link(struct dentry
*dentry
, struct nameidata
*nd
, void *ptr
)
309 link
= nd_get_link(nd
);
311 kmem_free(link
, MAXPATHLEN
);
315 zpl_link(struct dentry
*old_dentry
, struct inode
*dir
, struct dentry
*dentry
)
318 struct inode
*ip
= old_dentry
->d_inode
;
321 if (ip
->i_nlink
>= ZFS_LINK_MAX
)
325 ip
->i_ctime
= CURRENT_TIME_SEC
;
326 igrab(ip
); /* Use ihold() if available */
328 error
= -zfs_link(dir
, ip
, dname(dentry
), cr
);
334 d_instantiate(dentry
, ip
);
337 ASSERT3S(error
, <=, 0);
342 const struct inode_operations zpl_inode_operations
= {
343 .create
= zpl_create
,
345 .unlink
= zpl_unlink
,
346 .symlink
= zpl_symlink
,
350 .rename
= zpl_rename
,
351 .setattr
= zpl_setattr
,
352 .getattr
= zpl_getattr
,
353 .setxattr
= generic_setxattr
,
354 .getxattr
= generic_getxattr
,
355 .removexattr
= generic_removexattr
,
356 .listxattr
= zpl_xattr_list
,
359 const struct inode_operations zpl_dir_inode_operations
= {
360 .create
= zpl_create
,
361 .lookup
= zpl_lookup
,
363 .unlink
= zpl_unlink
,
364 .symlink
= zpl_symlink
,
368 .rename
= zpl_rename
,
369 .setattr
= zpl_setattr
,
370 .getattr
= zpl_getattr
,
371 .setxattr
= generic_setxattr
,
372 .getxattr
= generic_getxattr
,
373 .removexattr
= generic_removexattr
,
374 .listxattr
= zpl_xattr_list
,
377 const struct inode_operations zpl_symlink_inode_operations
= {
378 .readlink
= generic_readlink
,
379 .follow_link
= zpl_follow_link
,
380 .put_link
= zpl_put_link
,
383 const struct inode_operations zpl_special_inode_operations
= {
384 .setattr
= zpl_setattr
,
385 .getattr
= zpl_getattr
,
386 .setxattr
= generic_setxattr
,
387 .getxattr
= generic_getxattr
,
388 .removexattr
= generic_removexattr
,
389 .listxattr
= zpl_xattr_list
,